Import sql dump using the MySQL client

This is useful if you don’t have access to phpmyadmin on your server but have access to ssh and ftp. Or you have a huge sql dump like 10MB or higher that you cannot import directly on phpmyadmin. In my case the phpmyadmin directory was password protected by Apache and I don’t have the right password.

First upload the .sql file on your server using an FTP client and remember the path.

eg.
For Linux
/home/lopau/mydump.sql

for Windows
C:/wamp/www/lopau/mydump.sql

Login to your server using an SSH client like Putty.

On the command line access MySQL
$> mysql -u username -p password

replace username and password with yours.

On the MySQL client command line access and use your database.
$> use lopaudb;

Now to import your dump;
$> source /home/lopau/mydump.sql;

If successful you should see
Query OK, 13 rows affected (0.00 sec)

That easy.

Post Author: lopau

1 thought on “Import sql dump using the MySQL client

    Lysender

    (May 11, 2009 - 1:43 am)

    Wow! I didn’t know that source command yet. Gotta try this new one.

    All I know is:

    mysql -D db_name -u user_name -p < my_dump.sql

Leave a Reply

Your email address will not be published. Required fields are marked *