MySQL Cluster篇15 — 数据导入

概述

本章,您将学习 MySQL NDB Cluster 中的数据导入功能。

数据来源

数据的来源:

  • 使用 mysqldumpmysqlpump 命令将常规 MySQL 版本里的数据以逻辑备份的方式备份出来,备份文件的文件内容是 SQL 语句且常以 .sql 后缀结尾,您需要使用 mysql 命令将数据进行导入。

若您需要从 .sql 文件导入数据,通常不需要进行特别的操作,比如:

# 在 SQL 节点中进行操作,比如导入演示的 world.sql
Shell (192.168.100.16)> /usr/local/mysql/bin/mysql -h localhost -u root -p < /tmp/world.sql

若出现数据导入失败的情况,为了保证数据的一致性,您应该使用一个或多个 drop database ...drop table ... 语句来执行清理工作。

由于大部分逻辑备份中数据所使用的存储引擎为 InnoDB,因此您必须将表转换为 ndbcluster 存储引擎,使用到的 SQL 语法为 alter table ...,比如:

MySQL > use world;

MySQL > alter table city engine=ndbcluster ;

支持的存储引擎

MySQL > show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | YES     | Clustered, fault-tolerant tables                               | YES          | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| ndbinfo            | YES     | MySQL Cluster system information storage engine                | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
11 rows in set (0.00 sec)

提示
虽然 MySQL NDB Cluster 支持多个存储引擎,但是,使用非 ndbcluster 存储引擎的业务表并不会参与到集群的工作中。换言之,若要发挥 MySQL NDB Cluster 的集群功能(分布式事务、自动分片、跨节点同步、高可用故障恢复等),所有业务表 **必须** 使用 ndbcluster 存储引擎。

当前 SQL 节点配置文件的内容为:

Shell (192.168.100.16)> cat /etc/my.cnf
[mysqld]
ndbcluster

[mysql_cluster]
ndb-connectstring=192.168.100.10

由于未指定默认的存储引擎,因此默认使用的是 InnoDB 存储引擎:

Shell (192.168.100.16)> /usr/local/mysql/bin/mysql -h localhost -u root --password="Google-,Bing500"

MySQL > use db1;

MySQL > create table if not exists t2(
    name varchar(2)
    );

MySQL > show create table t2;
+-------+-------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                            |
+-------+-------------------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `name` varchar(2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-------------------------------------------------------------------------------------------------------------------------+

这在实际的生产环境下非常容易被忽略,因此需要修改 SQL 节点的 /etc/my.cnf (若存在多个 SQL 节点,则需要修改这些 SQL 节点的 /etc/my.cnf 文件):

Shell (192.168.100.16)> vim /etc/my.cnf
[mysqld]
ndbcluster
default-storage-engine=NDBCLUSTER

[mysql_cluster]
ndb-connectstring=192.168.100.10

Shell (192.168.100.16)> /usr/local/mysql/support-files/mysql.server restart

Shell (192.168.100.16)> /usr/local/mysql/bin/mysql -h localhost -u root --password="Google-,Bing500"

MySQL > use db1;

MySQL > create table if not exists t3(
    id int
    );

MySQL > show create table t3;
+-------+--------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                       |
+-------+--------------------------------------------------------------------------------------------------------------------+
| t3    | CREATE TABLE `t3` (
  `id` int DEFAULT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+--------------------------------------------------------------------------------------------------------------------+
Avatar photo

关于 陸風睿

GNU/Linux 从业者、开源爱好者、技术钻研者,撰写文档既是兴趣也是工作内容之一。Q - "281957576";WeChat - "jiulongxiaotianci",Github - https://github.com/jimcat8
用一杯咖啡支持我们,我们的每一篇[文档]都经过实际操作和精心打磨,而不是简单地从网上复制粘贴。期间投入了大量心血,只为能够真正帮助到您。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇