Linux: how to export and import a database

Posted by: 
Dominique De Cooman

Go to the location on your server where your file is using cd command

cd /var/www 

To see your location in the server directory tree use pwd command

For a list of all your databases:
$ mysql -u root -h localhost -p -Bse 'show databases'

To dump your database:

$ mysqldump -u root -h localhost -pmypassword faqs | database_name -9 > database_name.sql

To import your database:

mysql -u user -ppassword --default-character-set=utf8 database < "database_name.sql"

If you have a zip file you need to unzip it

gunzip name_file

Add new comment