文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

25.6.9 将数据导入 MySQL Cluster25.6.9 Importing Data Into MySQL Cluster

在设置新的 NDB Cluster 实例时,通常需要从现有的 NDB Cluster、MySQL 实例或其他来源导入数据。这些数据最常以以下一种或多种格式存在:It is common when setting up a new instance of NDB Cluster to need to import data from an existing NDB Cluster, instance of MySQL, or other source. This data is most often available in one or more of the following formats:

从 SQL 文件导入数据时,通常不需要强制使用事务或外键,临时禁用这些功能可以大大加快导入过程。可以使用 mysql 客户端来完成,无论是在客户端会话中,还是通过命令行调用。在 mysql 客户端会话中,你可以使用以下 SQL 语句来执行导入:When importing data from an SQL file, it is often not necessary to enforce transactions or foreign keys, and temporarily disabling these features can speed up the import process greatly. This can be done using the mysql client, either from a client session, or by invoking it on the command line. Within a mysql client session, you can perform the import using the following SQL statements:

SET ndb_use_transactions=0;
SET foreign_key_checks=0;

source path/to/dumpfile;

SET ndb_use_transactions=1;
SET foreign_key_checks=1;

以这种方式执行导入时,你必须在执行mysql客户端的source命令后重新启用ndb_use_transaction和foreign_key_checks。否则,同一会话中的后续语句可能在没有强制使用事务或外键约束的情况下执行,这可能导致数据不一致。When performing the import in this fashion, you must enable ndb_use_transaction and foreign_key_checks again following execution of the mysql client's source command. Otherwise, it is possible for later statements in same session may also be executed without enforcing transactions or foreign key constraints, and which could lead to data inconcsistency.

在系统终端中,你可以使用 mysql 客户端并带上 --init-command 选项来导入 SQL 文件,同时禁用事务和外键的强制执行,方法如下:From the system shell, you can import the SQL file while disabling enforcement of transaction and foreign keys by using the mysql client with the --init-command option, like this:

$> mysql --init-command='SET ndb_use_transactions=0; SET foreign_key_checks=0' < path/to/dumpfile

也可以将数据加载到一个 InnoDB 表中,然后使用 ALTER TABLE ... ENGINE NDB 将其转换为使用 NDB 存储引擎。你应该考虑到,特别是对于许多表,这可能需要进行多次此类操作;此外,如果使用了外键,你必须仔细注意 ALTER TABLE 语句的顺序,因为外键在使用不同 MySQL 存储引擎的表之间不起作用。It is also possible to load the data into an InnoDB table, and convert it to use the NDB storage engine afterwards using ALTER TABLE ... ENGINE NDB). You should take into account, especially for many tables, that this may require a number of such operations; in addition, if foreign keys are used, you must mind the order of the ALTER TABLE statements carefully, due to the fact that foreign keys do not work between tables using different MySQL storage engines.

您应该注意,本节之前描述的方法并未针对非常大的数据集或大事务进行优化。如果一个应用程序确实需要在正常操作中处理大事务或许多并发事务,您可能希望增加 MaxNoOfConcurrentOperations 数据节点配置参数的值,该参数会保留更多内存,以允许数据节点在其事务协调器意外停止时接管事务。You should be aware that the methods described previously in this section are not optimized for very large data sets or large transactions. Should an application really need big transactions or many concurrent transactions as part of normal operation, you may wish to increase the value of the MaxNoOfConcurrentOperations data node configuration parameter, which reserves more memory to allow a data node to take over a transaction if its transaction coordinator stops unexpectedly.

当对 NDB Cluster 表执行批量 DELETE 或 UPDATE 操作时,你也可能希望这样做。如果可能,尝试让应用程序分块执行这些操作,例如,通过在此类语句中添加 LIMIT。You may also wish to do this when performing bulk DELETE or UPDATE operations on NDB Cluster tables. If possible, try to have applications perform these operations in chunks, for example, by adding LIMIT to such statements.

如果数据导入操作由于任何原因未成功完成,您应准备执行任何必要的清理工作,包括可能执行一个或多个 DROP TABLE 语句、DROP DATABASE 语句,或两者兼施。不这样做可能会导致数据库处于不一致状态。If a data import operation does not complete successfully, for whatever reason, you should be prepared to perform any necessary cleanup including possibly one or more DROP TABLE statements, DROP DATABASE statements, or both. Failing to do so may leave the database in an inconsistent state.