How to export mysql database and restore using SSH

18 Oct

First login your server using SSH. Then run following command

mysqldump -u dbuser -p dbpassword dbname | gzip > dbname.sql.gz

Change dbuser, dbpassword and dbname with your database user name, password and database name.

If you want to restore the database on another server. Then we need to copy exported database on another server. We can copy files using scp.

We need to run following command to copy using scp.

scp dbname.sql.gz root@secondserverip:

If you use custom port then you need to specify port.

scp -P 80 dbname.sql.gz root@secondserverip:

Now login your second server and run following command.

gunzip < database.sql.gz | mysql -u dbuser -p dbpassword dbname

1736 Total Views 3 Views Today

Leave a Reply

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