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!

  • Search previous commands typedSearch previous commands typed If you want to see a collection of your previous commands used in Linux, you can always type ‘history’ for a listing of them. You can even search through history by grepping for the […]
  • mysqldump: Got error: 1142: SELECT,LOCK TABL command denied to user – for table ‘cond_instances’mysqldump: Got error: 1142: SELECT,LOCK TABL command denied to user – for table ‘cond_instances’ Have you seen this error before? This is because you’re trying to dump the performance_schema database while locking tables.

    The full error you received probably looks something […]

  • Move MySQL tmp directoryMove MySQL tmp directory You’ll eventually run into a client who has a crashed table in their database – this table will be pretty large – maybe even larger than the system’s default temporary directory (usually […]
  • Warning: Skipping the data of table mysql.event.Warning: Skipping the data of table mysql.event. Your MySQL script was running great, but then you started getting errors – If you get this warning when dumping the mysql database, it’s not a bug – MySQL did this on purpose because they […]
  • Learn the CSF command line options You have CSF installed and use the GUI to do most things.  (If you don’t have it installed yet, you can read our article on how to install csf).  BUT – knowing the csf (ConfigServer […]

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=""> 

*