10bet网址
MySQL 8.0参考手册
Related Documentation 下载本手册 Excerpts from this Manual

MySQL 8.0参考手册/....../ 将MySQL数据库复制到另一台计算机

2.11.14将MySQL数据库复制到另一台计算机

在您需要在不同架构之间传输数据库的情况下,您可以使用mysql.dump创建包含SQL语句的文件。然后,您可以将文件传输到另一个机器,并将其送至输入到mysql.客户。

Usemysqldump - help.看看有哪些选择。

笔记

如果在您创建转储的服务器上使用GTID(gtid_mode=ON), 默认,mysql.dumpincludes the contents of thegtid_executed在转储中设置将这些传输到新机器。这可以根据涉及的MySQL服务器版本而有所不同。检查描述mysqldump- set-gtid-pulgedoption to find what happens with the versions you are using, and how to change the behavior if the outcome of the default behavior is not suitable for your situation.

在两台机器之间移动数据库的最简单(虽然不是最快)的方式是在数据库所在的计算机上运行以下命令:

mysqladmin -h'other_hostname' 创造db_namemysql.dumpdb_name|mysql -h'other_hostname'db_name

如果要在慢速网络上从远程计算机复制数据库,则可以使用以下命令:

mysql.admin createdb_namemysqldump -h'other_hostname'--compressdb_name|mysql.db_name

You can also store the dump in a file, transfer the file to the target machine, and then load the file into the database there. For example, you can dump a database to a compressed file on the source machine like this:

mysql.dump --quickdb_name|gzip >db_name。gz

Transfer the file containing the database contents to the target machine and run these commands there:

mysql.admin createdb_nameGunzip <db_name。gz | mysqldb_name

你也可以使用mysql.dumpandmysql.import传输数据库。对于大型表,这比简单使用要快得多mysql.dump。In the following commands,DUMPDIRrepresents the full path name of the directory you use to store the output frommysql.dump

First, create the directory for the output files and dump the database:

MKDIR.DUMPDIRmysqldump --tab =DUMPDIRdb_name

Then transfer the files in theDUMPDIR目录到目标计算机上的某些相应目录并将文件加载到MySQL中:

mysql.admin createdb_name# create database catDUMPDIR/*.sql | mysqldb_name#在数据库中创建表mysqlimportdb_nameDUMPDIR/*.txt # load data into tables

不要忘记复制mysql.数据库,因为这是存储授权表的位置。您可能必须将命令运行为MySQL在新机器上的用户,直到您有mysql.database in place.

After you import themysql.数据库在新机上,执行mysql.admin flush-privileges因此,服务器重新加载授予表信息。