Importing a database dump into MySQL is a quick and easy process. However, there are a couple pitfalls that you should know about.
Here’s how to import a SQL dump into MySQL
Example user, password, and database name: kris qwerty12345 myDatabase
- If you don’t already have it, Create a SQL dump from the original database that you want to import.
- In the new database, create the database you want to import the data into.
mysql -u kris -p CREATE DATABASE myDatabase
It will prompt you for a password. Type it in and hit enter.
- Once created, import the file:
mysql -u kris -p myDatabase < /path/to/sql/dump/file.sql
It will prompt you again for a password.
Note: this command doesn’t give you any feedback as it is progressing (Unless there is an error, and you’ll then get an error message). Don’t worry.
If you accidentally type a “>” instead of the left-pointing “<” character, it will just hang and not give any feedback, which you will sit and stare at for a moment. Then you will cancel the command with Ctrl-C. Doing this actually corrupts the file, and you will then get the following error message next time you try to import the dump file:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Ctrl-C’ at line 1
If this happens to you, replace the dump file with a new one, because it is corrupted. Then re-run your import with the correct “<” character.