本地启动了三台虚拟机,分别是,cdh1(192.168.56.121)、cdh2(192.168.56.122)、cdh3(192.168.56.123)
其中cdh1是主库,cdh2、cdh3是从库
需要提前对三个库都把测试库创建好:
CREATE DATABASE `mytest` DEFAULT CHARACTER SET 'utf8mb4' DEFAULT COLLATE 'utf8mb4_general_ci';
然后我又给三个库建了一张表
CREATE TABLE IF NOT EXISTS `student` ( `id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR ( 100 ) NOT NULL, `sex` INT DEFAULT 1, `age` INT, PRIMARY KEY ( `id` ) ) ENGINE = INNODB DEFAULT CHARSET = utf8;
my.cnf
主库的my.cnf
需要修改下/etc/my.cnf的配置:
[root@cdh1 mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#该参数是指定禁止走dns反查功能,能大大加快MySQL连接的速度,注意有些文章中写到加入–skip-name-resolve,经验证,在CentOS5下加入–skip-name-resolve会导致mysql守护进程无法启动。估计在其他linux系统下是一样的,windows下没有测试,skip-name-resolve应该就可以。
skip-name-resolve
# 1.character_set_client主要用来设置客户端使用的字符集。
# 2.character_set_connection 主要用来设置连接数据库时的字符集,如果程序中没有指明连接数据库使用的字符集类型则按照这个字符集设置。
# 3.character_set_database 主要用来设置默认创建数据库的编码格式,如果在创建数据库时没有设置编码格式,就按照这个格式设置。
# 4.character_set_filesystem 文件系统的编码格式,把操作系统上的文件名转化成此字符集,character_set_client转换character_set_filesystem, 默认binary是不做任何转换的。
# 5.character_set_results 数据库给客户端返回时使用的编码格式,如果没有指明,使用服务器默认的编码格式。
# 6.character_set_server 服务器安装时指定的默认编码格式,这个变量建议由系统自己管理,不要人为定义。
# 7.character_set_system 数据库系统使用的编码格式,这个值一直是utf8,不需要设置,它是为存储系统元数据的编码格式。
# 8.character_sets_dir这个变量是字符集安装的目录。
character_set_server=utf8
init_connect='SET NAMES utf8' #用户在连接数据时,默认使用的是utf-8字符集进行通信。
#lower_case_table_names=0 表名存储为给定的大小和比较是区分大小写的
#lower_case_table_names = 1 表名存储在磁盘是小写的,但是比较的时候是不区分大小写
#lower_case_table_names=2 表名存储为给定的大小写但是比较的时候是小写的
lower_case_table_names=1
#当你使用主从拓扑时,一定要对所有MySQL实例都分别指定一个独特的互不相同的server-id。默认值为0,当server-id=0时,对于主机来说依然会记录二进制日志,但会拒绝所有的从机连接;对于从机来说则会拒绝连接其它实例。
server-id=1
#开启二进制日志,说明当前实例为主节点。在复制(replication)配置中,master必须打开此项
log-bin=mysql-bin
#二进制日志的模式与配置,一般开启二进制日志才会有此配置,所以从节点不会有这个配置
binlog-format=ROW
#指定主从复制的库名
binlog-do-db=mytest
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 64M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql #mysql文件指定路径
socket=/var/lib/mysql/mysql.sock #mysql的socket文件指定路径
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 #不开启链接,即表和数据不存在datadir以外的地址
log-error=/var/log/mysqld.log #mysql错误日志的指定路径
pid-file=/var/run/mysqld/mysqld.pid # mysql进程Id文件的指定路径
在MySQL中,复制二进制日志的方式主要有三种:
- 基于SQL语句的复制(Statement-Based Replication,SBR)。
- 基于行的复制(Row-Based Replication,RBR)。
- 混合模式复制(Mixed-Based Replication,MBR)。
对应的二进制日志模式有三种:Statement Level模式、Row Level模式和Mixed模式,其优点和缺点如表
MySQL默认使用Statement Level模式,推荐使用Mixed模式。对于一些特殊使用,可以考虑使用Row Level模式。例如,通过二进制日志同步数据的修改,会节省很多相关操作,所以对于二进制日志数据处理会变得非常轻松。如果采用INSERT、UPDATE、DELETE等直接操作表,则日志格式根据binlog_format的设定而记录。如果采用GRANT、REVOKE、SET PASSWORD等管理语句来操作表,那么一定要采用Statement Level模式记录
登录主库:
mysql> show variables like '%log_bin%';
+---------------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/mysql-bin |
| log_bin_index | /var/lib/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+--------------------------------+
6 rows in set (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
可以看到log_bin开启了,查看当前二进制文件状态的命令为show master status
,从库中由于没有开启二进制文件,所以就没有:
mysql> show master status;
Empty set (0.00 sec)
从库的my.cnf
看下从库的my.cnf配置
[root@cdh2 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
skip-name-resolve
character_set_server=utf8
init_connect='SET NAMES utf8'
lower_case_table_names=1
#关于从库的配置,server-id是核心配置,只需配置成和主库对应的server-id不同即可
server-id=2
#replicate-do-db选项的语法为:replicate-do-db=database_name。它允许从服务器仅复制database_name数据库。它也可以用于限制不需要复制的数据库列表,方法是在slave服务器配置文件中多次指定replicate-do-db选项。如果我们在主服务器上执行一些在其他数据库上的不相关修改,则可以通过使用该选项来确保这些修改不会在从服务器上执行
#换句话说此项配置用于指定数据库的复制,如果要复制多个,则配置多个replicate-do-db指定即可。
replicate-do-db=mytest
#中继日志(relay log)只在主从服务器架构的从服务器上存在。从服务器(Slave)为了与主服务器(Master)保持一致,要从主服务器读取二进制日志的内容,并且把读取到的信息写入本地的日志文件中,这个从服务器本地的日志文件就叫中继日志。然后,从服务器读取中继日志,并根据中继日志的内容对从服务器的数据进行更新,完成主从服务器的数据同步,起到了中介作用。
#如果想自定义日志的路径,可以在这里指定文件的具体路径。例如配置为:relay-log=/data/log/relaylog/myrelay,则会在/data/log/relaylog目录下面,生成myrelay.000001这样的relaylog日志文件
#开启relay-log就是要配置这个参数
relay-log=relay-log
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
从上面的配置中从库就没有开启二进制日志。
然后是一些必要的配置如:
server-id
replicate-do-db
relay-log
其中中继日志开启后,查看成没成功,可通过下面的命令查看验证,如果没开启,relay_log对应的value应该为空的。
mysql> show variables like '%relay%';
+---------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------+--------------------------------+
| max_relay_log_size | 0 |
| relay_log | relay-log |
| relay_log_basename | /var/lib/mysql/relay-log |
| relay_log_index | /var/lib/mysql/relay-log.index |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | FILE |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| sync_relay_log | 10000 |
| sync_relay_log_info | 10000 |
+---------------------------+--------------------------------+
11 rows in set (0.01 sec)
mysql>
登录主库:
mysql> show variables like '%log_bin%';
+---------------------------------+--------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------+
| log_bin | ON |
| log_bin_basename | /var/lib/mysql/mysql-bin |
| log_bin_index | /var/lib/mysql/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+--------------------------------+
6 rows in set (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
可以看到log_bin开启了,查看当前二进制文件状态的命令为show master status
,从库中由于没有开启二进制文件,所以就没有:
mysql> show master status;
Empty set (0.00 sec)
注意,修改完my.cnf配置后,需要重启mysql服务,即
service mysqld restart
,如果重启失败,需要查看报错日志,/var/log/mysqld.log
和/var/log/messages
这个两个地方进行查看
这个时候需要在从库中的mysql的控制台里执行相应的命令。如下:
mysql> reset slave;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to master_host='192.168.56.121',master_port=3306,master_user='root', master_password='123456',master_log_file='mysql-bin.000010' ,master_log_pos=219;
Query OK, 0 rows affected, 2 warnings (0.03 sec)
数据的第二个命令就是指定主库的连接信息以及复制的主动binlog文件和相应的POS位置,指定的是219,为什么是219因为我查了下主库的binlog日志文件,最近的插入记录是从那开始的,如下所示:
mysql> INSERT INTO student (name,sex,age) VALUES ('张三',1,18);
Query OK, 1 row affected (0.01 sec)
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000004 | 1974 |
| mysql-bin.000005 | 154 |
| mysql-bin.000006 | 154 |
| mysql-bin.000007 | 177 |
| mysql-bin.000008 | 413 |
| mysql-bin.000009 | 177 |
| mysql-bin.000010 | 778 |
+------------------+-----------+
7 rows in set (0.00 sec)
mysql> system mysqlbinlog /var/lib/mysql/mysql-bin.000010;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#231111 10:32:06 server id 1 end_log_pos 123 CRC32 0xcda570d3 Start: binlog v 4, server v 5.7.32-log created 231111 10:32:06 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
pudOZQ8BAAAAdwAAAHsAAAABAAQANS43LjMyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAACm505lEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AdNwpc0=
'/*!*/;
# at 123
#231111 10:32:06 server id 1 end_log_pos 154 CRC32 0xe3265f58 Previous-GTIDs
# [empty]
# at 154
#231111 11:10:31 server id 1 end_log_pos 219 CRC32 0x0abf6480 Anonymous_GTID last_committed=0 sequence_number=1 rbr_only=no
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 219
#231111 11:10:31 server id 1 end_log_pos 495 CRC32 0xc8e5a2a3 Query thread_id=2 exec_time=0 error_code=0
use `mytest`/*!*/;
SET TIMESTAMP=1699672231/*!*/;
SET @@session.pseudo_thread_id=2/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1436549152/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table if not exists `student` (`id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR ( 100 ) NOT NULL, `sex` INT DEFAULT 1, `age` INT, PRIMARY KEY ( `id` ) ) ENGINE = INNODB DEFAULT CHARSET = utf8
/*!*/;
# at 495
#231111 11:11:24 server id 1 end_log_pos 560 CRC32 0x388f7839 Anonymous_GTID last_committed=1 sequence_number=2 rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 560
#231111 11:11:24 server id 1 end_log_pos 634 CRC32 0xd78113a4 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1699672284/*!*/;
BEGIN
/*!*/;
# at 634
#231111 11:11:24 server id 1 end_log_pos 691 CRC32 0x65990a83 Table_map: `mytest`.`student` mapped to number 109
# at 691
#231111 11:11:24 server id 1 end_log_pos 747 CRC32 0xd3b5afcd Write_rows: table id 109 flags: STMT_END_F
BINLOG '
3PBOZRMBAAAAOQAAALMCAAAAAG0AAAAAAAEABm15dGVzdAAHc3R1ZGVudAAEAw8DAwIsAQyDCpll
3PBOZR4BAAAAOAAAAOsCAAAAAG0AAAAAAAEAAgAE//ABAAAABgDlvKDkuIkBAAAAEgAAAM2vtdM=
'/*!*/;
# at 747
#231111 11:11:24 server id 1 end_log_pos 778 CRC32 0x3bf1fa1a Xid = 18
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
mysql>
回到从库的mysql;
再次使用命令show slave status\G;
查询后,就会展示我需要的信息:
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.56.121
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 219
Relay_Log_File: relay-log.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: mytest
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 219
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
上面展示的信息是从库信息,包括读取主库的日志文件,中继日志(relay_log)等。但是判断主从复制有没有部署成功的依据是Slave_IO_Running
以及Slave_SQL_Running
都为YES才算成功,目前显示的都为关闭状态,所以还需要继续配置。
大概率没有启动slave试下:
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.56.121
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 219
Relay_Log_File: relay-log.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB: mytest
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 219
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1593
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID:
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 231111 14:33:14
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
Slave_IO_Running
还为NO,可能的情况在一篇博客上找到了答案,博客他给了三个可能性:
- MySQL的uuid是唯一的,查看主从机器的uuid是否唯一
- 确认server-id是否唯一。
- 因为从库MySQL重启导致二进制文件位置从库和主库不一致。
我直接选择最后一个解决方案进行重启,然后发现解决不了,然后从第一个可能性进行排查,果然,两个机器的UUID是一样的。。。
主库:
[root@cdh1 ~]# cat /var/lib/mysql/auto.cnf
[auto]
server-uuid=fb8d483c-47eb-11eb-ba17-0800276c3e95
[root@cdh1 ~]#
从库:
[root@cdh2 ~]# cat /var/lib/mysql/auto.cnf
[auto]
server-uuid=fb8d483c-47eb-11eb-ba17-0800276c3e95
[root@cdh2 ~]#
现在对从库的uuid进行手动修改下,我选择修改最后一个数字,应该没啥问题
[root@cdh2 ~]# cat /var/lib/mysql/auto.cnf
[auto]
server-uuid=fb8d483c-47eb-11eb-ba17-0800276c3e95
[root@cdh2 ~]# vim /var/lib/mysql/auto.cnf
[root@cdh2 ~]# cat /var/lib/mysql/auto.cnf
[auto]
server-uuid=fb8d483c-47eb-11eb-ba17-0800276c3e96
[root@cdh2 ~]#
ok,对mysql进行重启。
[root@cdh2 ~]# service mysqld restart;
Redirecting to /bin/systemctl restart mysqld.service
[root@cdh2 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.121
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 778
Relay_Log_File: relay-log.000004
Relay_Log_Pos: 879
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: mytest
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 778
Relay_Log_Space: 1080
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: fb8d483c-47eb-11eb-ba17-0800276c3e95
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
搞定~
现在看下从库mytest库中,student表中的数据。
mysql> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from student;
+----+--------+------+------+
| id | name | sex | age |
+----+--------+------+------+
| 1 | 张三 | 1 | 18 |
+----+--------+------+------+
1 row in set (0.00 sec)
mysql>
之前主库已经插了一条数据,所以已经成功同步过来了。
然后继续往主库插入一条数据,
mysql> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> INSERT INTO student (name,sex,age) VALUES ('李四',2,19);
Query OK, 1 row affected (0.00 sec)
mysql>
然后在从库查询下:
mysql> select * from student;
+----+--------+------+------+
| id | name | sex | age |
+----+--------+------+------+
| 1 | 张三 | 1 | 18 |
| 2 | 李四 | 2 | 19 |
+----+--------+------+------+
2 rows in set (0.00 sec)
mysql>
到此主从复制流程算是通了。
标签:主从复制,set,log,relay,server,Master,mysql From: https://www.cnblogs.com/bibibao/p/17826918.html