由于先前做过其他数据库实验,环境是server2为master, server1和server3为slave
mysql> grant replication slave on *.* to 'tutu'@'172.25.54.%' identified by '5820hhXM!@#';
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> change master to master_host='172.25.54.3',master_user='tutu',master_password='5820hhXM!@#',master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.17 sec)
若出现Slave_SQL_Running: No
(原因:数据不同步,
在 server3 上 reset msater;
server1 上 shop slave; –> reset slave; –>start slave;)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database test;
Query OK, 1 row affected (0.13 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> create table userlist (
-> username varchar(15) not null,
-> password varchar(25) not null);
Query OK, 0 rows affected (0.41 sec)
mysql> desc userlist;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(15) | NO | | NULL | |
| password | varchar(25) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> insert into userlist values ('user1','147');
Query OK, 1 row affected (0.09 sec)
mysql> insert into userlist values ('user2','258');
Query OK, 1 row affected (0.16 sec)
mysql> insert into userlist values ('user3','369');
Query OK, 1 row affected (0.08 sec)
mysql> select * from userlist;
+----------+----------+
| username | password |
+----------+----------+
| user1 | 147 |
| user2 | 258 |
| user3 | 369 |
+----------+----------+
3 rows in set (0.00 sec)
mysql> Bye
[root@server2 ~]#
[root@server3 ~]# vim /etc/my.cnf
[root@server3 ~]# cat /etc/my.cnf | tail -n 11
server-id=3
log-bin=mysql-bin
log-slave-updates
gtid_mode=ON
enforce-gtid-consistency=true
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON
[root@server3 ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[root@server3 ~]# mysql -p5820hhXM\!\@#
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 23
Server version: 5.7.17-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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;
+----+-------------+---------------+------+------------------+-------+---------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+---------------+------+------------------+-------+---------------------------------------------------------------+------------------+
| 1 | system user | | NULL | Connect | 58 | Slave has read all relay log; waiting for more updates | NULL |
| 2 | system user | | NULL | Connect | 60 | Waiting for master to send event | NULL |
| 3 | system user | | NULL | Connect | 83590 | Waiting for an event from Coordinator | NULL |
| 4 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 6 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 7 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 8 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 9 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 10 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 11 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 12 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 13 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 16 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 17 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 18 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 19 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 20 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 21 | system user | | NULL | Connect | 60 | Waiting for an event from Coordinator | NULL |
| 22 | tutu | server1:48836 | NULL | Binlog Dump GTID | 5 | Master has sent all binlog to slave; waiting for more updates | NULL |
| 23 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+-------------+---------------+------+------------------+-------+---------------------------------------------------------------+------------------+
20 rows in set (0.00 sec)