The mysqldump
command is a useful tool for backing up a MySQL database. One way to use mysqldump
to copy a database from one server to another is by using shell pipes and SSH.
Here’s an example of how you can use mysqldump
to copy a database named “mydatabase” from a remote server to your local machine:
ssh user@remote-server "mysqldump mydatabase" | mysql -u localuser -p mydatabase
In this example, the mysqldump
command is run on the remote server, and its output is redirected to the local machine through an SSH pipe. The output is then passed to the mysql
command, which imports the data into the local database named “mydatabase”. The -u
option is used to specify the MySQL user, and the -p
option is used to prompt for a password.
This method can be useful when you want to copy a database from one server to another without having to transfer large data files. The only data that is transferred over the network is the output of the mysqldump
command, which can be significantly smaller than a raw data file.
Note that this method requires that you have SSH access to the remote server and that the remote server has access to the MySQL database. Also, be sure to use the correct username and password for both the remote server and the MySQL database.