Import MySQL database from command line

Rob —  July 9, 2014 — 1 Comment

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:

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:

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!

Related posts from Linux Brigade!

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

*