I have a .sql
file with an export from phpMyAdmin
. I want to import it into a different server using the command line.
I have a Windows Server 2008 R2 installation. I placed the .sql
file on the C drive, and I tried this command
database_name < file.sql
It is not working I get syntax errors.
- How can I import this file without a problem?
- Do I need to create a database first?
Regarding the time taken for importing huge files: most importantly, it takes more time because the default setting of MySQL is
autocommit = true
. You must set that off before importing your file and then check how import works like a gem.You just need to do the following thing:
To dump a database into a SQL file use the following command
To import a SQL file into a database (make sure you are in the same directory as the SQL file or supply the full path to the file)
Go to the directory where you have MySQL.
Also to dump all databases, use the
-all-databases
option, and no databases’ name needs to be specified anymore.Or you can use some GUI clients like SQLyog to do this.
Import a database
Go to drive:
MySQL login
It will ask for pwd. Enter it:
Select the database
Provide the file name
Similarly to https://stackoverflow.com/a/17666285/1888983
Key differences for me:
-p
and the passwordRunning fedora 26 with MariaDB.
I kept running into the problem where the database wasn't created.
I fixed it like this