Tuesday, June 18, 2013

Import / Export MySQL Database using Ubuntu terminal

To import .sql file into MySQL database
mysql -u mysql_user -p dabase_name < /path/import_file_name.sql
It will ask for the password, enter the mysql password and your sql script will be executed.

To export a database and gzip it, use
mysqldump -h localhost -u mysql_user -pMysql_password database_name | gzip > /path/export_file_name_$(date +%m-%d-%Y).sql.gz
$(date +%m-%d-%Y) is optional. It inserts today's date in the file name. You can also use this export command without   $(date +%m-%d-%Y)

 mysqldump -h localhost -u mysql_user -pMysql_password database_name | gzip > /path/export_file_name_$(date +%m-%d-%Y).sql.gz

I hope it helped. Feel free to comment...

No comments:

Post a Comment

Feel free to comment. Your comments are considered...