mysqldump - Copy Database Using Shell Pipes and SSH

www.lau‮utt‬ri.com
mysqldump - Copy Database Using Shell Pipes and SSH

The mysqldump utility can be used to create a backup of a MySQL database by generating a SQL script that can be used to recreate the database. You can use shell pipes and SSH to copy the database to a remote server or to create a backup on the local server.

Here are the steps to use mysqldump to copy a database using shell pipes and SSH:

  1. Connect to the MySQL server. To connect to the MySQL server, you can use the mysql utility:
mysql -u root -p

Enter the password for the root user when prompted.

  1. Dump the database. To dump the database using mysqldump, you can use the following syntax:
mysqldump -u username -p database_name > dump.sql

Replace username with the username of the MySQL user and database_name with the name of the database to be dumped. The dump.sql file will contain the SQL script that can be used to recreate the database.

  1. Copy the database to a remote server. To copy the database to a remote server using SSH, you can use the scp utility and the following syntax:
scp dump.sql username@remote_server:/path/to/dump.sql

Replace username with the username of the remote user, remote_server with the hostname or IP address of the remote server, and /path/to/dump.sql with the desired path to the dump.sql file on the remote server.

  1. Import the database on the remote server. To import the database on the remote server, you will need to connect to the MySQL server on the remote server and use the mysql utility to execute the dump.sql script. You can use the following syntax:
mysql -u username -p database_name < dump.sql

Replace username with the username of the MySQL user on the remote server, database_name with the name of the database to be imported, and dump.sql with the path to the dump.sql file on the remote server.

Using mysqldump and shell pipes and SSH, you should be able to easily copy a MySQL database to a remote server or create a backup on the local server.

Created Time:2017-10-30 10:17:55  Author:lautturi