原理:
1. 在master机器上的操作:
当master的数据发生变化时,此事件的变化会按照顺序写入==bin-log==中。当slave连接到master时,master机器会为slave开启==bin-log dump==线程。当master的bin-log发生变化时,bin-log dump线程会通知slave,并将相应的binlog内容发送给slave。
2. 在slave机器上的操作:
当主从同步开启的时候,slave会创建两个线程:==**I/O线程**==。该线程连接到master机器,master机器上的bin-log dump线程会将bin-log的内容发送给该I/O线程。该I/O线程接收到bin-log内容后,再将内容写入到本地的==relay log==;==**sql线程**==,该线程读取到I/O线程写入的relay log,并且根据relay log的内容对slave数据库做相应的操作。
3. 从库生成两个线程,一个I/O线程,一个SQL线程;
I/O线程去请求主库的binlog,并将得到的binlog日志写到relay log(中继日志) 文件中;
主库会生成一个 log dump 线程,用来给从库I/O线程传binlog;
SQL 线程会读取relay log文件中的日志,并解析成具体操作,来实现主从的操作一致,而最终使得数据一致;
搭建过程:
attention:搭建MySQL主从同步前,需要分别在主库和从库上安装并配置好MySQL数据库!!!
环境: IP:192.168.10.21 主机名:server1 版本:MySQL5.7 角色:Master
IP:192.168.10.22 主机名:server2 版本:MySQL5.7 角色:Slave
配置master:192.168.10.21
配置/etc/my.cnf
[root@server1 ~]# vim /etc/my.cnf
2 [client]
3 port=3306
4 socket=/data/mysql/mysql.sock
5
6 [mysqld]
7 character‐set‐server=utf8
8 collation‐server=utf8_general_ci
9
10 skip‐name‐resolve
11 user=mysql
12 port=3306
13 basedir=/usr/local/mysql57
14 datadir=/data/mysql
15 tmpdir=/tmp
16 socket=/data/mysql/mysql.sock
17
18 log‐error=/data/mysql/mysqld.log
19 pid‐file=/data/mysql/mysqld.pid
20
21 log‐bin=mysql‐bin‐master #启用二进制日志
22 server‐id=1 #本机数据库ID 标示
23 binlog‐do‐db=testdb #可以被从服务器复制的库, 二进制需要同步的数据库名
24 binlog‐ignore‐db=mysql #不可以被从服务器复制的库
25 lower_case_table_names=1
26 #注意:Linux下部署安装MySQL,默认不忽略表名大小写,需要手动到/etc/my.cnf 下配置 lower_case_table_names=1 使Linux环境下MySQL忽略表名大小写,否则使用MyCAT的时候会提示找不到表的错误!
[root@server1 ~]# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
创建要同步的数据库并创建表
[root@server1 ~]# mysql -uroot -p111
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 3
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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> create database testdb;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> CREATE TABLE TABLE666 (bTypeID int,bName char(16),price int,publishing char(16));
Query OK, 0 rows affected (0.00 sec)
授权
mysql> grant replication slave on *.* to slave@"192.168.10.%" identified by "111";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show master status;
+-------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------------+----------+--------------+------------------+-------------------+
| mysql-bin-master.000002 | 843 | testdb | mysql | |
+-------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> show binlog events\G
*************************** 1. row ***************************
Log_name: mysql-bin-master.000001
Pos: 4
Event_type: Format_desc
Server_id: 1
End_log_pos: 123
Info: Server ver: 5.7.19-log, Binlog ver: 4
*************************** 2. row ***************************
Log_name: mysql-bin-master.000001
Pos: 123
Event_type: Previous_gtids
Server_id: 1
End_log_pos: 154
Info:
*************************** 3. row ***************************
Log_name: mysql-bin-master.000001
Pos: 154
Event_type: Anonymous_Gtid
Server_id: 1
End_log_pos: 219
Info: SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
*************************** 4. row ***************************
Log_name: mysql-bin-master.000001
Pos: 219
Event_type: Query
Server_id: 1
End_log_pos: 398
Info: ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*832EB84CB764129D05D498ED9CA7E5CE9B8F83EB'
*************************** 5. row ***************************
Log_name: mysql-bin-master.000001
Pos: 398
Event_type: Anonymous_Gtid
Server_id: 1
End_log_pos: 463
Info: SET @@SESSION.GTID_NEXT= 'ANONYMOUS'
*************************** 6. row ***************************
Log_name: mysql-bin-master.000001
Pos: 463
Event_type: Query
Server_id: 1
End_log_pos: 550
Info: flush privileges
*************************** 7. row ***************************
Log_name: mysql-bin-master.000001
Pos: 550
Event_type: Stop
Server_id: 1
End_log_pos: 573
Info:
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@server1 ~]# ls /data/mysql
auto.cnf ib_logfile1 mysql-bin-master.000002 mysql.sock testdb
ib_buffer_pool ibtmp1 mysql-bin-master.index mysql.sock.lock
ibdata1 mysql mysqld.log performance_schema
ib_logfile0 mysql-bin-master.000001 mysqld.pid sys
如果不知道这个文件在哪可以cat /etc/my.cnf查看"datadir=什么"
导出数据库并传给从服务器
[root@server1 ~]# cd /usr/local/src/mysql-5.7.19
[root@server1 mysql-5.7.19]# mysqldump -uroot -p111 -B testdb > testdb.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@server1 mysql-5.7.19]# ls
BUILD CPackConfig.cmake libbinlogevents mysys_ssl strings
client CPackSourceConfig.cmake libbinlogstandalone packaging support-files
cmake CTestTestfile.cmake libevent plugin testclients
CMakeCache.txt dbug libmysql rapid testdb.sql
CMakeFiles Docs libmysqld README unittest
cmake_install.cmake Doxyfile-perfschema libservices regex VERSION
CMakeLists.txt extra make_dist.cmake scripts VERSION.dep
cmd-line-utils include Makefile source_downloads vio
config.h.cmake info_macros.cmake man sql win
configure.cmake INSTALL mysql-test sql-common zlib
COPYING install_manifest.txt mysys storage
[root@server1 mysql-5.7.19]# scp testdb.sql 192.168.10.22:/root
The authenticity of host '192.168.10.22 (192.168.10.22)' can't be established.
ECDSA key fingerprint is 02:58:f1:1a:ea:0a:59:21:af:83:2a:2c:8e:3a:d5:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.22' (ECDSA) to the list of known hosts.
root@192.168.10.22's password: (输入另外一台机的密码)
testdb.sql 100% 2027 2.0KB/s 00:00
配置Slave 192.168.10.22
配置/etc/my.cnf
1 [root@server2 ~]# vim /etc/my.cnf
2 [client]
3 port=3306
4 socket=/data/mysql/mysql.sock
5
6 [mysqld]
7 ctestdbracter‐set‐server=utf8
8 collation‐server=utf8_general_ci
9
10 skip‐name‐resolve
11 user=mysql
12 port=3306
13 basedir=/usr/local/mysql57
14 datadir=/data/mysql
15 tmpdir=/tmp
16 socket=/data/mysql/mysql.sock
17
18 log‐error=/data/mysql/mysqld.log
19 pid‐file=/data/mysql/mysqld.pid
20
21 server‐id=2
22 #从服务器ID号,不要和主ID相同 ,如果设置多个从服务器,每个从服务器必须有一个唯一的server‐id值,必须与主服务器的以及其它从服务器的不相同。可以认为server‐id值类似于IP地址:这些ID值能唯一识别复制服务器群集中的每个服务器实例。
23 lower_case_table_names=1
24 #注意:Linux下部署安装MySQL,默认不忽略表名大小写,需要手动到/etc/my.cnf 下配置 lower_case_table_names=1 使Linux环境下MySQL忽略表名大小写,否则使用MyCAT的时候会提示找不到表的错误!
[root@server2 ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
两台数据库服务器MySQL的版本要一致
[root@server1 ~]# mysql -uroot -p111
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 7
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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 variables like "%version%";
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| innodb_version | 5.7.19 |
| protocol_version | 10 |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1 |
| version | 5.7.19-log |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+---------------------+
8 rows in set (0.00 sec)
[root@server2 ~]# mysql -uroot -p111
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 9
Server version: 5.7.19 Source distribution
Copyright (c) 2000, 2017, 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 variables like "%version%";
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| innodb_version | 5.7.19 |
| protocol_version | 10 |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1 |
| version | 5.7.19 |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+---------------------+
8 rows in set (0.01 sec)
测试连接到主数据库是否成功
[root@server2 ~]# cd /data/mysql/
[root@server2 mysql]# mysql -uslave -p111 -h 192.168.10.21
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 8
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
#这个时候看不到testdb数据库是正常的
向testdb数据库导入数据
[root@server2 mysql]# cd
[root@server2 ~]# mysql -uroot -p111 < testdb.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@server2 ~]# mysql -uroot -p111
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 11
Server version: 5.7.19 Source distribution
Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> use testdb;
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_testdb |
+------------------+
| table666 |
+------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
指定主数据库,然后重启slave这台机器
[root@server2 ~]# mysql -uroot -p111
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 12
Server version: 5.7.19 Source distribution
Copyright (c) 2000, 2017, 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> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to master_host='192.168.10.21',master_user='slave',master_password='111';
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.21
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin-master.000002
Read_Master_Log_Pos: 1153
Relay_Log_File: server2-relay-bin.000003
Relay_Log_Pos: 381
Relay_Master_Log_File: mysql-bin-master.000002
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1007
Last_Error: Error 'Can't create database 'testdb'; database exists' on query. Default database: 'testdb'. Query: 'create database testdb'
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 2212
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: 1007
Last_SQL_Error: Error 'Can't create database 'testdb'; database exists' on query. Default database: 'testdb'. Query: 'create database testdb'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: cf7b706e-64ca-11ed-a114-000c293661ae
Master_Info_File: /data/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: 221115 20:05:58
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)
#有可能出现以上错误,解决方法如下:
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> set global sql_slave_skip_counter=1;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.21
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin-master.000002
Read_Master_Log_Pos: 1153
Relay_Log_File: server2-relay-bin.000005
Relay_Log_Pos: 327
Relay_Master_Log_File: mysql-bin-master.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: 1153
Relay_Log_Space: 709
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: cf7b706e-64ca-11ed-a114-000c293661ae
Master_Info_File: /data/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)
Slave_IO_Running: Yes 负责与主机的I/O通信
Slave_SQL_Running: Yes 负责自己的slave mysql进程
两个均为yes就成功了!!!
再到主数据库上查看状态
[root@server1 ~]# mysql -uroot -p111
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 12
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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 processlist\G
*************************** 1. row ***************************
Id: 7
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: starting
Info: show processlist
*************************** 2. row ***************************
Id: 11
User: slave
Host: 192.168.10.22:50506
db: NULL
Command: Binlog Dump
Time: 207
State: Master has sent all binlog to slave; waiting for more updates
Info: NULL
2 rows in set (0.00 sec)
测试主从同步
[root@server1 ~]# mysql -uroot -p111
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 12
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| testdb |
+--------------------+
5 rows in set (0.00 sec)
mysql> use testdb;
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_testdb |
+------------------+
| table666 |
+------------------+
1 row in set (0.00 sec)
mysql> select * from table666;
Empty set (0.00 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('1','Linux1','70','WM');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('2','Linux2','71','WM');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('3','Linux3','72','WM');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('4','MySQL1','73','QH');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('5','MySQL2','74','QH');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO table666(bTypeId,bName,price,publishing) VALUES('6','MySQL3','78','QH');
Query OK, 1 row affected (0.01 sec)
mysql> select * from table666;
+---------+--------+-------+------------+
| bTypeID | bName | price | publishing |
+---------+--------+-------+------------+
| 1 | Linux1 | 70 | WM |
| 2 | Linux2 | 71 | WM |
| 3 | Linux3 | 72 | WM |
| 4 | MySQL1 | 73 | QH |
| 5 | MySQL2 | 74 | QH |
| 6 | MySQL3 | 78 | QH |
+---------+--------+-------+------------+
6 rows in set (0.00 sec)
mysql> exit
Bye
[root@server2 ~]# mysql -uroot -p111
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 12
Server version: 5.7.19 Source distribution
Copyright (c) 2000, 2017, 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> select * from testdb.table666;
+---------+--------+-------+------------+
| bTypeID | bName | price | publishing |
+---------+--------+-------+------------+
| 1 | Linux1 | 70 | WM |
| 2 | Linux2 | 71 | WM |
| 3 | Linux3 | 72 | WM |
| 4 | MySQL1 | 73 | QH |
| 5 | MySQL2 | 74 | QH |
| 6 | MySQL3 | 78 | QH |
+---------+--------+-------+------------+
6 rows in set (0.01 sec)
主库
[root@server1 ~]# mysql -uroot -p111
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 13
Server version: 5.7.19-log Source distribution
Copyright (c) 2000, 2017, 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> select * from table666;
ERROR 1046 (3D000): No database selected
mysql> use testdb
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 table666;
+---------+--------+-------+------------+
| bTypeID | bName | price | publishing |
+---------+--------+-------+------------+
| 1 | Linux1 | 70 | WM |
| 2 | Linux2 | 71 | WM |
| 3 | Linux3 | 72 | WM |
| 4 | MySQL1 | 73 | QH |
| 5 | MySQL2 | 74 | QH |
| 6 | MySQL3 | 78 | QH |
+---------+--------+-------+------------+
6 rows in set (0.00 sec)
mysql> delete from table666 where bName="MySQL3";
Query OK, 1 row affected (0.00 sec)
mysql> select * from table666;
+---------+--------+-------+------------+
| bTypeID | bName | price | publishing |
+---------+--------+-------+------------+
| 1 | Linux1 | 70 | WM |
| 2 | Linux2 | 71 | WM |
| 3 | Linux3 | 72 | WM |
| 4 | MySQL1 | 73 | QH |
| 5 | MySQL2 | 74 | QH |
+---------+--------+-------+------------+
5 rows in set (0.00 sec)
mysql>
从库
mysql> select * from testdb.table666;
+---------+--------+-------+------------+
| bTypeID | bName | price | publishing |
+---------+--------+-------+------------+
| 1 | Linux1 | 70 | WM |
| 2 | Linux2 | 71 | WM |
| 3 | Linux3 | 72 | WM |
| 4 | MySQL1 | 73 | QH |
| 5 | MySQL2 | 74 | QH |
+---------+--------+-------+------------+
5 rows in set (0.00 sec)
==至此,MySQL主从同步搭建成功!!!==