Import export mysql database command line superfast

This tutorial about importing and exporting database command line superfast. If you have big mysql database and you try to import, you may feel lot’s of trouble in regular method and it also takes too much time to upload from local to server then running queries. But recently I tried command line method to upload database on server and then import 2GB big sql file with in 5 minute.



You can use command line method if you have full control of your server like you have your VPS or cloud server.

First copy the sql file on server by SSH of any other method, I prefer to use SSH because it is more secure and fast to copying files from local computer to server.

Importing sql files command line

mysql -u [Database_username] -p [Database_name] < Sql_file.sql

Where
-u: Database user name
-p: Databse name where you have to run import.
After running above command it’ll ask database password and hit enter.
mysql-import


Exporting sql files command line

mysqldump -u [Database_username] -p [Database_name] > backup_database.sql

-u: Database user name
-p: Databse name where you have to run export and take backup.
After running above command it’ll ask database password and hit enter.
mysql_export_dump

Exporting sql files command line In compress format(.sql.gz)

mysqldump -u [Database_username] -p [Database_name] | gzip > backup_database.sql.gz

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.