赞
踩
GTID即全局事务ID (global transaction identifier), 其保证为每一个在主上提交的事务在复制集群中可以生成一个唯一的ID。GTID最初由google实现,官方MySQL在5.6才加入该功能。mysql主从结构在一主一从情况下对于GTID来说就没有优势了,而对于2台主以上的结构优势异常明显,可以在数据不丢失的情况下切换新主。使用GTID需要注意: 在构建主从复制之前,在一台将成为主的实例上进行一些操作(如数据清理等),通过GTID复制,这些在主从成立之前的操作也会被复制到从服务器上,引起复制失败。也就是说通过GTID复制都是从最先开始的事务日志开始,即使这些操作在复制之前执行。比如在server1上执行一些drop、delete的清理操作,接着在server2上执行change的操作,会使得server2也进行server1的清理操作。
GTID实际上是由UUID+TID (即transactionId)组成的。其中UUID(即server_uuid) 产生于auto.conf文件(cat /data/mysql/data/auto.cnf),是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增,所以GTID能够保证每个MySQL实例事务的执行(不会重复执行同一个事务,并且会补全没有执行的事务)。GTID在一组复制中,全局唯一。 下面是一个GTID的具体形式 :
mysql> show master status; +------------------+----------+--------------+------------------+------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+------------------------------------------+ | mysql_bin.000001 | 1150 | | | b35dffb0-fc03-11ec-920f-000c29f6e7cf:1-4 | +------------------+----------+--------------+------------------+------------------------------------------+ 1 row in set (0.01 sec) D:b35dffb0-fc03-11ec-920f-000c29f6e7cf:1-4 UUID:b35dffb0-fc03-11ec-920f-000c29f6e7cf transactionId:1-4 在整个复制架构中GTID 是不变化的,即使在多个连环主从中也不会变。 例如:ServerA --->ServerB ---->ServerC GTID从在ServerA ,ServerB,ServerC 中都是一样的。
了解了GTID的格式,通过UUID可以知道这个事务在哪个实例上提交的。通过GTID可以极方便的进行复制结构上的故障转移,新主设置,这就很好地解决了下面这个图所展现出来的问题。
如图, Server1(Master)崩溃,根据从上show slave status获得Master_log_File/Read_Master_Log_Pos的值,Server2(Slave)已经跟上了主,Server3(Slave)没有跟上主。这时要是把Server2提升为主,Server3变成Server2的从。这时在Server3上执行change的时候需要做一些计算。
这个问题在5.6的GTID出现后,就显得非常的简单。由于同一事务的GTID在所有节点上的值一致,那么根据Server3当前停止点的GTID就能定位到Server2上的GTID。甚至由于MASTER_AUTO_POSITION功能的出现,我们都不需要知道GTID的具体值,直接使用CHANGE MASTER TO MASTER_HOST=‘xxx’, MASTER_AUTO_POSITION命令就可以直接完成failover的工作。
GTID和Binlog的关系
GTID 重要参数的持久化
参数 | comment |
---|---|
gtid_executed | 执行过的所有GTID |
gtid_purged | 丢弃掉的GTID |
gtid_mode | GTID模式 |
gtid_next | session级别的变量,下一个gtid |
gtid_owned | 正在运行的GTID |
enforce_gtid_consistency | 保证GTID安全的参数 |
开启GTID的必备条件
gtid_mode=on (必选)
enforce-gtid-consistency=1 (必选)
log_bin=mysql-bin (可选) #高可用切换,最好开启该功能
log-slave-updates=1 (可选) #高可用切换,最好打开该功能
从服务器连接到主服务器之后,把自己执行过的GTID (Executed_Gtid_Set: 即已经执行的事务编码) 、获取到的GTID (Retrieved_Gtid_Set: 即从库已经接收到主库的事务编号) 发给主服务器,主服务器把从服务器缺少的GTID及对应的transactions发过去补全即可。当主服务器挂掉的时候,找出同步最成功的那台从服务器,直接把它提升为主即可。如果硬要指定某一台不是最新的从服务器提升为主, 先change到同步最成功的那台从服务器, 等把GTID全部补全了,就可以把它提升为主了。
GTID是MySQL 5.6的新特性,可简化MySQL的主从切换以及Failover。GTID用于在binlog中唯一标识一个事务。当事务提交时,MySQL Server在写binlog的时候,会先写一个特殊的Binlog Event,类型为GTID_Event,指定下一个事务的GTID,然后再写事务的Binlog。主从同步时GTID_Event和事务的Binlog都会传递到从库,从库在执行的时候也是用同样的GTID写binlog,这样主从同步以后,就可通过GTID确定从库同步到的位置了。也就是说,无论是级联情况,还是一主多从情况,都可以通过GTID自动找点儿,而无需像之前那样通过File_name和File_position找点儿了。
简而言之,GTID的工作流程为:
环境说明:
数据库角色 | IP | 应用与系统版本 | 有无数据 | 主机名 |
---|---|---|---|---|
主数据库 | 192.168.229.130 | centos8/redhat8 mysql-5.7 | 无数据 | node1 |
从数据库 | 192.168.229.145 | centos8/redhat8 mysql-5.7 | 无数据 | node2 |
# 下载二进制格式的mysql软件包 [root@node1 ~]# cd /opt/ [root@node1 opt]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz [root@node1 opt]# ls mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz # 解压,并改为mysql ## 解压到/usr/local/ [root@node1 opt]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@node1 local]# ls bin etc games include lib lib64 libexec mysql-5.7.37-linux-glibc2.12-x86_64 sbin share src # 改名为mysql [root@node1 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql [root@node1 local]# ls bin etc games include lib lib64 libexec mysql sbin share src # 创建mysql系统用户,没有家目录,不需要登录 [root@node1 ~]# useradd -r -M -s /sbin/nologin mysql [root@node1 ~]# id mysql uid=995(mysql) gid=992(mysql) groups=992(mysql) #修改目录/usr/local/mysql的属主属组 [root@node1 local]# chown -R mysql.mysql mysql [root@node1 local]# ll mysql/ -d drwxr-xr-x. 9 mysql mysql 129 Jul 5 09:18 mysql/ # 添加环境变量(你也可以直接vim 写到/etc/profile.d/mysql.sh下面) [root@node1 ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@node1 ~]# source /etc/profile.d/mysql.sh # 刷新,让其生效 [root@node1 ~]# which mysqld /usr/local/mysql/bin/mysqld # 配置include ## 软链接到/usr/include/mysql,叫mysql [root@node1 ~]# ln -s /usr/local/mysql/include /usr/include/mysql # 配置 man 文档 [root@node1 ~]# vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /usr/local/mysql/man # 添加这条 # 映射库文件 [root@node1 ~]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@node1 ~]# ldconfig # 让其生效 # 建立数据存放目录 [root@node1 ~]# mkdir /opt/data # 设置所有者和所属组为mysql [root@node1 ~]# chown -R mysql.mysql /opt/data/ [root@node1 ~]# ll /opt/data/ -d drwxr-xr-x. 2 mysql mysql 6 Jun 28 16:36 /opt/data/ # 初始化数据库 [root@node1 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/ .....省略 root@node1: z!r;kBSfX5uu # 临时密码 # 请注意,这个命令的最后会生成一个临时密码,此处密码是 z!r;kBSfX5uu # 再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到 # 生成配置文件 [root@node1 ~]# vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # 配置服务启动脚本 [root@node1 ~]# cd /usr/local/mysql/support-files/ # 复制 [root@node1 support-files]# cp mysql.server mysqld # 更改所有者和所属组为MySQL [root@node1 support-files]# chown -R mysql.mysql mysqld [root@node1 support-files]# ll mysqld -d -rwxr-xr-x. 1 mysql mysql 10576 Jul 5 09:44 mysqld # 启动mysql [root@node1 ~]# /usr/local/mysql/support-files/mysqld start Starting MySQL.Logging to '/opt/data/node1.err'. SUCCESS! [root@node1 ~]# ps -ef|grep mysql root 10496 1 0 09:46 pts/1 00:00:00 /bin/sh /usr/local/mysql/binmysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid mysql 10696 10496 1 09:46 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=node1.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306 root 10726 1754 0 09:46 pts/1 00:00:00 grep --color=auto mysql [root@node1 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* # 安装依赖包 (不安装登录不了) [root@node1 ~]# dnf -y install ncurses-compat-libs # 使用临时密码登录 [root@node1 ~]# mysql -uroot -p'z!r;kBSfX5uu' ....省略 # 看到这个ok mysql> # 修改密码 mysql> set password = password('runtime123!'); ## 退出使用设置好的密码登录 [root@node1 ~]# mysql -uroot -pruntime123! ....省略 mysql> # 配置service文件,目的让MySQL能够开机自启 # 配置service文件之前关闭关闭防火墙和SElinux # 关闭防火墙和SElinux [root@node1 ~]# systemctl disable --now firewalld # 临时关闭 [root@node1 ~]# setenforce 0 # 永久关闭 [root@node1 ~]# vim /etc/selinux/config [root@node1 ~]# head -7 /etc/selinux/config | tail -1 SELINUX=disabled # 把它改为disabled # 杀死 mysql 进程 [root@node1 ~]# pkill mysqld # 复制到当前目录下、更改它 [root@node1 ~]# cd /usr/lib/systemd/system/ [root@node1 system]# cp sshd.service mysqld.service [root@node1 system]# vim mysqld.service [Unit] Description=mysql server daemon After=network.target sshd-keygen.target [Service] Type=forking ExecStart=/usr/local/mysql/support-files/mysqld start ExecStop=/usr/local/mysql/support-files/mysqld stop ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target # 刷新程序、让其生效 [root@node1 ~]# systemctl daemon-reload # 查看状态 [root@node1 ~]# systemctl status mysqld ● mysql.service - mysql server daemon Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled) Active: inactive (dead) # 设置为开机自启、并立马启动 [root@node1 ~]# systemctl enable --now mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service→ /usr/lib/systemd/system/mysqld.service. [root@node1 ~]# systemctl status mysqld ● mysqld.service - mysql server daemon Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor> Active: active (running) since Tue 2022-07-05 09:54:22 CST; 2s ago Process: 10855 ExecStart=/usr/local/mysql/support-files/mysqld start (co> Main PID: 10868 (mysqld_safe) .....省略 [root@node1 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:*
# 下载二进制格式的mysql软件包 [root@node2 ~]# cd /opt/ [root@node2 opt]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz [root@node2 opt]# ls mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz # 解压,并改为mysql ## 解压到/usr/local/ [root@node2 opt]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@node2 local]# ls bin etc games include lib lib64 libexec mysql-5.7.37-linux-glibc2.12-x86_64 sbin share src # 改名为mysql [root@node2 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql [root@node2 local]# ls bin etc games include lib lib64 libexec mysql sbin share src # 创建mysql系统用户,没有家目录,不需要登录 [root@node2 ~]# useradd -r -M -s /sbin/nologin mysql [root@node2 ~]# id mysql uid=995(mysql) gid=992(mysql) groups=992(mysql) #修改目录/usr/local/mysql的属主属组 [root@node2 local]# chown -R mysql.mysql mysql [root@node2 local]# ll mysql/ -d drwxr-xr-x. 9 mysql mysql 129 Jul 5 09:18 mysql/ # 添加环境变量(你也可以直接vim 写到/etc/profile.d/mysql.sh下面) [root@node2 ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@node2 ~]# source /etc/profile.d/mysql.sh # 刷新,让其生效 [root@node2 ~]# which mysqld /usr/local/mysql/bin/mysqld # 配置include ## 软链接到/usr/include/mysql,叫mysql [root@node2 ~]# ln -s /usr/local/mysql/include /usr/include/mysql # 配置 man 文档 [root@node2 ~]# vim /etc/man_db.conf MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /usr/local/mysql/man # 添加这条 # 映射库文件 [root@node2 ~]# vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@node2 ~]# ldconfig # 让其生效 # 建立数据存放目录 [root@node2 ~]# mkdir /opt/data # 设置所有者和所属组为mysql [root@node2 ~]# chown -R mysql.mysql /opt/data/ [root@node2 ~]# ll /opt/data/ -d drwxr-xr-x. 2 mysql mysql 6 Jun 28 16:36 /opt/data/ # 初始化数据库 [root@node2 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/ .....省略 root@node2:!MAsgd+h9pgl # 临时密码 # 请注意,这个命令的最后会生成一个临时密码,此处密码是 !MAsgd+h9pgl # 再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到 # 生成配置文件 [root@node2 ~]# vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # 配置服务启动脚本 [root@node2 ~]# cd /usr/local/mysql/support-files/ # 复制 [root@node2 support-files]# cp mysql.server mysqld # 更改所有者和所属组为MySQL [root@node2 support-files]# chown -R mysql.mysql mysqld [root@node2 support-files]# ll mysqld -d -rwxr-xr-x. 1 mysql mysql 10576 Jul 5 09:44 mysqld # 启动mysql [root@node2 ~]# /usr/local/mysql/support-files/mysqld start Starting MySQL.Logging to '/opt/data/node1.err'. SUCCESS! [root@node2 ~]# ps -ef|grep mysql root 10496 1 0 09:46 pts/1 00:00:00 /bin/sh /usr/local/mysql/binmysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid mysql 10696 10496 1 09:46 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=node1.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306 root 10726 1754 0 09:46 pts/1 00:00:00 grep --color=auto mysql [root@node2 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* # 安装依赖包 (不安装登录不了) [root@node2 ~]# dnf -y install ncurses-compat-libs # 使用临时密码登录 [root@node2 ~]# mysql -uroot -p'!MAsgd+h9pgl' ....省略 # 看到这个ok mysql> # 修改密码 mysql> set password = password('runtime123!'); ## 退出使用设置好的密码登录 [root@node2 ~]# mysql -uroot -pruntime123! ....省略 mysql> # 配置service文件,目的让MySQL能够开机自启 # 配置service文件之前关闭关闭防火墙和SElinux # 关闭防火墙和SElinux [root@node2 ~]# systemctl disable --now firewalld # 临时关闭 [root@node2 ~]# setenforce 0 # 永久关闭 [root@node2 ~]# vim /etc/selinux/config [root@node2 ~]# head -7 /etc/selinux/config | tail -1 SELINUX=disabled # 把它改为disabled # 杀死 mysql 进程 [root@node2 ~]# pkill mysqld # 复制到当前目录下、更改它 [root@node2 ~]# cd /usr/lib/systemd/system/ [root@node2 system]# cp sshd.service mysqld.service [root@node2 system]# vim mysqld.service [Unit] Description=mysql server daemon After=network.target sshd-keygen.target [Service] Type=forking ExecStart=/usr/local/mysql/support-files/mysqld start ExecStop=/usr/local/mysql/support-files/mysqld stop ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target # 刷新程序、让其生效 [root@node2 ~]# systemctl daemon-reload # 查看状态 [root@node2 ~]# systemctl status mysqld ● mysql.service - mysql server daemon Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled) Active: inactive (dead) # 设置为开机自启、并立马启动 [root@node2 ~]# systemctl enable --now mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service→ /usr/lib/systemd/system/mysqld.service. [root@node2 ~]# systemctl status mysqld ● mysqld.service - mysql server daemon Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor> Active: active (running) since Tue 2022-07-05 09:54:22 CST; 2s ago Process: 10855 ExecStart=/usr/local/mysql/support-files/mysqld start (co> Main PID: 10868 (mysqld_safe) .....省略 [root@node2 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:*
主库配置。vi /etc/my.cnf,添加以下配置,重启mysql。
log-bin=mysql_bin server-id=10 gtid_mode=on enforce-gtid-consistency=true log-slave-updates=on [root@node1 ~]# cat /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION log-bin = mysql_bin # 添加 server-id = 10 # 添加 gtid_mode = on # 添加 enforce-gtid-consistency = true # 添加 log-slave-updates = on # 添加 # 重启mysql [root@node1 ~]# systemctl restart mysqld
从库配置。vi /etc/my.cnf, 添加以下配置,重启mysql。
server-id=20 relay-log=myrelay gtid_mode=on enforce-gtid-consistency=true log-slave-updates=on read_only=on master-info-repository=TABLE relay-log-info-repository=TABLE [root@node2 ~]# cat /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION server-id = 20 relay-log = myrelay gtid_mode = on enforce-gtid-consistency = true log-slave-updates = on read_only = on master-info-repository = TABLE relay-log-info-repository = TABLE # 重启mysql [root@node1 ~]# systemctl restart mysqld
主库授权复制用户。
set global validate_password_policy=0; # 这是在centos7/redhat7操作,在centos8/redhat8里不用做
set global validate_password_length=1; # 这是在centos7/redhat7操作,在centos8/redhat8里不用做
grant replication slave on *.* to 'tom'@'%' identified by 'tom123!';
# 登录进去操作
[root@node1 ~]# mysql -uroot -pruntime123!
mysql> grant replication slave on *.* to 'tom'@'%' identified by 'tom123!';
Query OK, 0 rows affected, 1 warning (0.01 sec)
# 你可以把% 号改为某个ip地址。
从库设置要同步的主库信息,并开启同步。
change master to master_host='192.168.229.130', \ # ip 是主库ip master_port=3306,master_user='tom',master_password='tom123!', \ master_auto_position=1; # 登录进去操作 [root@node2 ~]# mysql -uroot -pruntime123! mysql> change master to master_host='192.168.229.130', master_port=3306,master_user='tom',master_password='tom123!', master_auto_position=1; Query OK, 0 rows affected, 2 warnings (0.00 sec) # 启动 mysql> start slave; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.229.130 Master_User: tom Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql_bin.000001 Read_Master_Log_Pos: 436 Relay_Log_File: myrelay.000002 Relay_Log_Pos: 649 Relay_Master_Log_File: mysql_bin.000001 Slave_IO_Running: Yes # 这个一定要为yes Slave_SQL_Running: Yes # 这个一定要为yes Replicate_Do_DB: Replicate_Ignore_DB: .......省略N
配置完之后,通过查看slave的状态,可以看是否配置成功。同时可以在主库进行一些操作,提交一些事务(insert,update),之后数据就会自动同步到从库。
node1操作
# 创建数据库school,在里面创建一张表 mysql> create database school; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | school | | sys | +--------------------+ 5 rows in set (0.01 sec) mysql> use school; Database changed mysql> create table tom( -> id int(11) not null primary key auto_increment, -> name varchar(20) not null -> )charset utf8; Query OK, 0 rows affected (0.01 sec) mysql> insert tom(name) values('陈冠希'),('张国荣'),('刘德华'); Query OK, 3 rows affected (0.02 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from tom; +----+-----------+ | id | name | +----+-----------+ | 1 | 陈冠希 | | 2 | 张国荣 | | 3 | 刘德华 | +----+-----------+ 3 rows in set (0.01 sec)
node2 查看是否同步
# 登录进去 [root@node2 ~]# mysql -uroot -pruntime123! ..........省略 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | school | # 数据库已存在 | sys | +--------------------+ 5 rows in set (0.01 sec) # 进去数据库里查看表 Database changed mysql> show tables; +------------------+ | Tables_in_school | +------------------+ | tom | +------------------+ 1 row in set (0.00 sec) mysql> select * from tom; +----+-----------+ | id | name | +----+-----------+ | 1 | 陈冠希 | | 2 | 张国荣 | | 3 | 刘德华 | +----+-----------+ 3 rows in set (0.00 sec)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。