Home  >  Article  >  Database  >  How to copy a table or database from one MySQL server to another MySQL server?

How to copy a table or database from one MySQL server to another MySQL server?

WBOY
WBOYforward
2023-09-06 14:45:071284browse

How to copy a table or database from one MySQL server to another MySQL server?

If we want to copy a table or database from one MySQL server to another MySQL server, use mysqldump# with the database name and table name. ##.

Run the following commands on the source host. This will dump the complete database into a

dump.txt file.

$ mysqldump -u root -p database_name table_name > dump.txt
password *****

We can copy the complete database without using the specific table names explained above.

Now, on another host ftp the dump.txt file and use the following command. Before running this command, make sure we have created database_name on the target server.

$ mysql -u root -p database_name < dump.txt
password *****

Another way to achieve this without using intermediate files is to send the output of the MySQL dump directly over the network to the remote MySQL server. If we can connect to both servers from the host where the source database is located, use the following command (make sure we have access to both servers).

$ mysqldump -u root -p database_name \
| mysql -h other-host.com database_name

In mysqldump, the command half connects to the local server and writes the dump output to a pipe. The remaining half of the command connects to the remote MySQL server at other-host.com. It reads the piped input and sends each statement to the other-host.com server.

The above is the detailed content of How to copy a table or database from one MySQL server to another MySQL server?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete