Import MySQL DB via CLI

mysql -u account_name -p db_name < /path/to/import/file/mysql.sql
^^ from the *nix command line

Sometimes you need to specify the host (typically it's either 127.0.0.1 or localhost) like this:

mysql -u account_name -p -h localhost db_name < /path/to/import/file/mysql.sql
^^ from the *nix command line

Now enter the specified account's mysql password and you're on your way!

In the instance you're having issues with your import, another way to import (will require access and proper privs), sometimes you just want it to run and not worry about errors (for instance when an insert or two in a dump are greater than the buffer). The handy function to just "make it work" (ie: NOT FOR PRODUCTION USE!!!) is source in the mysql cli -- check it out:

mysql> source /path/to/db/export.sql;
^^ from the mysql command line

That'll treat the file as a list of commands and run each one individually. If a few of them don't work, it keeps moving on and finishes everything it can... now that's BLAMO

Leave a Reply