CentOS搭建MySQL主从复制,读写分离(2)

提示
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
说明配置成功了

9、测试主从服务器是否能同步 
插入 修改 删除 增加字段 修改字段 增加表自己测试都可以

[linuxidc@server22 ~]$mysql -uroot -p123456 mysql> create database test; mysql> create table user(id int); mysql> insert into user values(1),(2),(3),(4),(5),(6); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from user; +----+ | id | +----+ | 1 | | 2 | +----+ 2rows in set (0.00 sec) mysql> select * from user; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | +----+ 6 rows in set (0.00 sec) mysql> update user set id=11 where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from user; +----+ | id | +----+ | 11 | | 2 | | 3 | | 4 | | 5 | | 6 | +----+ 6 rows in set (0.00 sec) mysql> delete from user where id=2; Query OK, 1 row affected (0.00 sec) mysql> select * from user; +----+ | id | +----+ | 11 | | 3 | | 4 | | 5 | | 6 | +----+ 5 rows in set (0.00 sec) mysql> alter table user add name varchar(50); Query OK, 5 rows affected (0.01 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> select * from user; +----+------+ | id | name | +----+------+ | 11 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +----+------+ 5 rows in set (0.00 sec) mysql> ALTER TABLE user MODIFY COLUMN name VARCHAR(200); Query OK, 5 rows affected (0.01 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> desc user; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | NO | | NULL | | | name | varchar(200) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> create table user2(id int); Query OK, 0 rows affected (0.01 sec) mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | test | | user | | user2 | +----------------+ 3 rows in set (0.00 sec) mysql>




在从服务器查看是否同步过来 如果一致说明成功

mysql> use test; Database changed mysql> select * from user; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | +----+ 2 rows in set (0.00 sec) mysql> select * from user; +----+ | id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | +----+ 6 rows in set (0.00 sec) mysql> select * from user; +----+ | id | +----+ | 11 | | 2 | | 3 | | 4 | | 5 | | 6 | +----+ 6 rows in set (0.00 sec) mysql> select * from user; +----+ | id | +----+ | 11 | | 3 | | 4 | | 5 | | 6 | +----+ 5 rows in set (0.00 sec) mysql> select * from user; +----+------+ | id | name | +----+------+ | 11 | NULL | | 3 | NULL | | 4 | NULL | | 5 | NULL | | 6 | NULL | +----+------+ 5 rows in set (0.00 sec) mysql> desc user; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id | int(11) | NO | | NULL | | | name | varchar(200) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | test | | user | | user2 | +----------------+ 3 rows in set (0.00 sec) mysql> mysql binlog日志查看: show binlog events\G; *************************** 12. row *************************** Log_name: mysql-bin.000007 Pos: 985 Event_type: Query Server_id: 1 End_log_pos: 1075 Info: use `test`; delete from user where id=2 *************************** 13. row *************************** Log_name: mysql-bin.000007 Pos: 1075 Event_type: Query Server_id: 1 End_log_pos: 1175 Info: use `test`; alter table user add name varchar(50) *************************** 14. row *************************** Log_name: mysql-bin.000007 Pos: 1175 Event_type: Query Server_id: 1 End_log_pos: 1287 Info: use `test`; ALTER TABLE user MODIFY COLUMN name VARCHAR(200) *************************** 15. row *************************** Log_name: mysql-bin.000007 Pos: 1287 Event_type: Query Server_id: 1 End_log_pos: 1376 Info: use `test`; create table user2(id int) 15 rows in set (0.00 sec)

本文永久更新链接地址

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d1feff77745da8ef6a2a78d5b96356e0.html