You’ll need to import a database via command line from time to time – I’ll normally opt for this anyway. After seeing how easy it is, you’ll probably end up using the command line instead as well (instead of phpmyadmin, etc..).
Let’s set up some things.
DB host: localhost
Database: username_db
User: username_user
Password: mypassword
MySQL Dump: /home/mydump.sql
Ok.. so you’ve ssh’d into your server and you’re sitting at a prompt. Run this command:
1 |
mysql -u username_user -p username_db < /home/mydump.sql |
Then hit [Enter]
Then type in the password..
Then, just wait.. when the prompt returns, it’s finished.
If we break it down:
-u = username
-p = ask for password
Let’s say you use a remote MySQL server though…
DB host: myhost.server.com
Database: username_db
User: username_user
Password: mypassword
MySQL Dump: /home/mydump.sql
Simply add the -h flag to specify your host:
1 |
mysql -h myhost.server.com -u username_user -p username_db < /home/mydump.sql |
You will want to make sure that username_user has access to connect to your mysql server from the machine you are running this command from.
Hope this helped!