六、检查复制状态
这个必须要说一下,Slave_IO_Running、Slave_SQL_Running同时为yes才说明同步环境搭建ok
当然现实环境中(往往第一次搭建的时候会出很多问题),不会那么顺利,当不全为yes的时候:第一查看mysql.log日志,第二结合下边3个命令慢慢调:stop slave(停止复制)、reset slave(重置)、start slave
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.130
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 154
Relay_Log_File: ct-test1-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 154
Relay_Log_Space: 530
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: 101
Master_UUID: 3f93c491-39ee-11e6-8726-000c29916128
Master_Info_File: /mysql/data/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)
ok,搭建完成,很简单吧,下边做一下同步测试
我们在主库上执行建库、建表、插入数据等操作,然后从备库检查是否同步过去
I、主库上的操作
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database zxt;
Query OK, 1 row affected (0.04 sec)
mysql> use zxt;
Database changed
mysql> create tables tab_test(id1 varchar(10));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tables tab_test(id1 varchar(10))' at line 1
mysql> create table tab_test(id1 varchar(10));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into tab_test values ('12345');
Query OK, 1 row affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
II.备库上检查结果如下:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zxt |
+--------------------+
5 rows in set (0.00 sec)
mysql> use zxt
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> show tables;
+---------------+
| Tables_in_zxt |
+---------------+
| tab_test |
+---------------+
1 row in set (0.00 sec)
mysql> select * from tab_test;
+-------+
| id1 |
+-------+
| 12345 |
+-------+
1 row in set (0.00 sec)
mysql>