mysql5.7 server id_三台mysql5.7服务器互作主从配置案例
一、架構(gòu)
三臺(tái)msyql服務(wù)器221,222,223,每臺(tái)服務(wù)器開兩個(gè)實(shí)例,3306作為主庫(kù),3307作為另外一臺(tái)服務(wù)器的從庫(kù)
二、每臺(tái)服務(wù)器安裝雙實(shí)例
參照:https://www.cnblogs.com/sky-cheng/p/10919447.html
進(jìn)行雙實(shí)例安裝
三、每臺(tái)服務(wù)器的3306實(shí)例創(chuàng)建一個(gè)復(fù)制賬號(hào)
在172.28.5.221上
[root@push-5-221 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 16Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'XXXXXXX';
Query OK,0 rows affected, 1 warning (0.00sec)
mysql>
在172.28.5.222上
[root@push-5-222 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 11Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'XXXXXXXX';
Query OK,0 rows affected, 1 warning (0.01sec)
mysql>flush privileges;
Query OK,0 rows affected (0.00sec)
mysql>
在172.28.5.223上
[root@push-5-223 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 7Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'xxxxxxxx';
Query OK,0 rows affected, 1 warning (0.00sec)
mysql>flush privileges;
Query OK,0 rows affected (0.00sec)
mysql>
三、主從配置
1、首先設(shè)置好每個(gè)3306mysql實(shí)例的server_id參數(shù)為本機(jī)IP地址最后一位,3307實(shí)例server_id參數(shù)為本機(jī)IP地址最后一位再加端口號(hào)
在172.28.5.221服務(wù)器的3306配置文件中打開日志文件設(shè)置
[root@push-5-221 ~]# vim /etc/mysql/my-3306.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3306datadir=/home/mysql-5.7.26/data/3306socket=/var/lib/mysql/3306/mysql.sock
server_id=2213306log-bin=master-221binlog_format=row
#skip-grant-tables
symbolic-links=0pid-file=/var/run/mysqld/3306/mysqld.pid
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
[mysqld_safe]
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
server_id=221 設(shè)置server_id
log-bin=master-221 設(shè)置log_bin日志文件名
binlog_format=row 指定日志格式為row
2、重啟3306實(shí)例,使配置生效
[root@push-5-221 ~]# mysqladmin -uroot -p -S /var/lib/mysql/3306/mysql.sock shutdown
[root@push-5-221 ~]# mysqld_safe --defaults-file=/etc/mysql/my-3306.cnf &[1] 3459[root@push-5-221 ~]# 2019-05-27T02:55:18.758733Z mysqld_safe Logging to '/home/mysql-5.7.26/log/3306/mysqld.log'.2019-05-27T02:55:18.813602Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data/3306
3、客戶端連接
^C
[root@push-5-221 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26-log MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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.
4、顯示server_id參數(shù)
mysql> show variables like '%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2213306 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.00 sec)
5、顯示主庫(kù)狀態(tài)
mysql>show master status\G;*************************** 1. row ***************************File: master-221.000002Position:154Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:1 row in set (0.00sec)
ERROR:
No query specified
此時(shí),需要記住上面的參數(shù): ?File: master-221.000001 ??Position: 154 ,日志文件名和偏移量,需要在從庫(kù)上做主從設(shè)置時(shí)要用到這兩個(gè)參數(shù)
6、從庫(kù)設(shè)置
在172.28.5.222服務(wù)器上的3307配置文件
[mysqld]
# innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3307datadir=/home/mysql-5.7.26/data/3307socket=/var/lib/mysql/3307/mysql.sock
server_id=2223307symbolic-links=0pid-file=/var/run/mysqld/3307/mysqld.pid
log-error=/home/mysql-5.7.26/log/3307/mysqld.log
[mysqld_safe]
log-error=/home/mysql-5.7.26/log/3307/mysqld.log
7、重啟3307實(shí)例,使配置生效
[root@push-5-222 ~]# mysqladmin -uroot -p -S /var/lib/mysql/3307/mysql.sock shutdown
[root@push-5-222 ~]# mysqld_safe --defaults-file=/etc/mysql/my-3307.cnf &[1] 23445[root@push-5-222 ~]# 2019-05-27T03:11:33.550199Z mysqld_safe Logging to '/home/mysql-5.7.26/log/3307/mysqld.log'.2019-05-27T03:11:33.610157Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data/3307
8、查看相應(yīng)參數(shù)
[root@push-5-222 ~]# mysql -uroot -p -S /var/lib/mysql/3307/mysql.sock
mysql> show variables like '%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2223307 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.00 sec)
9、執(zhí)行從庫(kù)命令
mysql>change master to-> master_host='172.28.5.221',-> master_port=3306,-> master_user='repl',-> master_password='xxxxxxxx',-> master_log_file='master-221.000002',-> master_log_pos=154;
Query OK,0 rows affected, 2 warnings (0.31 sec)
10、啟動(dòng)從庫(kù)
mysql>start slave;
Query OK,0 rows affected (0.05 sec)
11、顯示從庫(kù)狀態(tài)
mysql>start slave;
Query OK,0 rows affected (0.05sec)
mysql>show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waitingformaster to send event
Master_Host:172.28.5.221Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: master-221.000002Read_Master_Log_Pos:154Relay_Log_File: push-5-222-relay-bin.000002Relay_Log_Pos:321Relay_Master_Log_File: master-221.000002Slave_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:0Last_Error:
Skip_Counter:0Exec_Master_Log_Pos:154Relay_Log_Space:533Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:2213306Master_UUID: 3e61e5be-7dff-11e9-8945-6c2b5992e632
Master_Info_File:/home/mysql-5.7.26/data/3307/master.infoSQL_Delay:0SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waitingfor more updates
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
同步線程都已經(jīng)啟動(dòng)成功、
Exec_Master_Log_Pos: 154 同步主庫(kù)日志文件偏移量跟主庫(kù)的日志文件偏移量相同,說明已經(jīng)完全同步
12、測(cè)試同步
在172.28.5.221上創(chuàng)建test庫(kù)和test表,并插入一條記錄
mysql>create database test;
Query OK,1 row affected (0.12sec)
mysql>show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+mysql>use test;
Database changed
mysql> create table test( uid int, name varchar(20));
Query OK,0 rows affected (0.43sec)
mysql> insert into test(uid,name)values(1,'aaaa');
Query OK,1 row affected (0.14sec)
mysql> select *from test;+------+------+
| uid | name |
+------+------+
| 1 | aaaa |
+------+------+
1 row in set (0.00 sec)
此時(shí),在172.28.5.222上連接從庫(kù)3307
[root@push-5-222 ~]# mysql -uroot -p -S /var/lib/mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 5Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql>show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00sec)
mysql>use test;
Reading table informationforcompletion 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_test |
+----------------+
| test |
+----------------+
1 row in set (0.00sec)
mysql> select *from test;+------+------+
| uid | name |
+------+------+
| 1 | aaaa |
+------+------+
1 row in set (0.00 sec)
已經(jīng)跟主庫(kù)數(shù)據(jù)同步成功了。
同樣在172.28.5.222上將3306配置文件打開
[mysqld]
#innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3306datadir=/home/mysql-5.7.26/data/3306socket=/var/lib/mysql/3306/mysql.sock
server_id=2223306log-bin=master-222binlog_format=row
#skip-grant-tables
symbolic-links=0pid-file=/var/run/mysqld/3306/mysqld.pid
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
[mysqld_safe]
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
重啟3306實(shí)例
[root@push-5-222 ~]# mysqladmin -uroot -p -S /var/lib/mysql/3306/mysql.sock shutdown
Enter password:
[root@push-5-222 ~]# mysqld_safe --defaults-file=/etc/mysql/my-3306.cnf &[2] 24587[root@push-5-222 ~]# 2019-05-27T03:29:21.804192Z mysqld_safe Logging to '/home/mysql-5.7.26/log/3306/mysqld.log'.2019-05-27T03:29:21.864191Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data/3306[root@push-5-222 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26-log MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> show variables like '%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2223306 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.01sec)
mysql>show msater status\G;
ERROR1064 (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 'msater status' at line 1ERROR:
No query specified
mysql>show master status\G;*************************** 1. row ***************************File: master-222.000001Position:154Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:1 row in set (0.00sec)
ERROR:
No query specified
顯示主庫(kù)狀態(tài)
在172.28.5.223服務(wù)器上打開3307配置文件,將其設(shè)置為172.28.5.222的3306的從庫(kù)
[root@push-5-223 ~]# vim /etc/mysql/my-3307.cnf
[mysqld]
# innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3307datadir=/home/mysql-5.7.26/data/3307socket=/var/lib/mysql/3307/mysql.sock
server_id=2233307#log-bin=master-223#binlog_format=row
#skip-grant-tables
symbolic-links=0pid-file=/var/run/mysqld/3307/mysqld.pid
log-error=/home/mysql-5.7.26/log/3307/mysqld.log
[mysqld_safe]
log-error=/home/mysql-5.7.26/log/3307/mysqld.log
客戶端連接,設(shè)置從庫(kù)命令
[root@push-5-223 ~]# mysql -uroot -p -S /var/lib/mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 3Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> show variables like '%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2233307 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.00sec)
mysql>change master to-> master_host='172.28.5.222',-> master_port=3306,-> master_user='repl',-> master_password='xxxxxx',-> master_log_file='master-222.000001',-> master_log_pos=154;
Query OK,0 rows affected, 2 warnings (0.36 sec)
啟動(dòng)從庫(kù)
mysql>start slave;
Query OK,0 rows affected (0.05sec)
mysql>show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waitingformaster to send event
Master_Host:172.28.5.222Master_User: repl
Master_Port:3306Connect_Retry:60Master_Log_File: master-222.000001Read_Master_Log_Pos:154Relay_Log_File: push-5-223-relay-bin.000002Relay_Log_Pos:321Relay_Master_Log_File: master-222.000001Slave_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:0Last_Error:
Skip_Counter:0Exec_Master_Log_Pos:154Relay_Log_Space:533Until_Condition: None
Until_Log_File:
Until_Log_Pos:0Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:0Last_IO_Error:
Last_SQL_Errno:0Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:2223306Master_UUID: de99b6b7-8018-11e9-9a45-6c2b5992e6d2
Master_Info_File:/home/mysql-5.7.26/data/3307/master.infoSQL_Delay:0SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waitingfor moreupdates
Master_Retry_Count:86400Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:0Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
此時(shí),從庫(kù)已經(jīng)啟動(dòng),并且同步線程啟動(dòng)成功,同步完畢
測(cè)試數(shù)據(jù)
在172.28.5.222的3306上創(chuàng)建test庫(kù)個(gè)test表,并插入一條數(shù)據(jù)
mysql>create database test;
Query OK,1 row affected (0.11sec)
mysql>use test;
Database changed
mysql> create table test (uid int,name varchar(20));
Query OK,0 rows affected (0.26sec)
mysql> insert into test values(1,'bbbb');
Query OK,1 row affected (0.15sec)
mysql> select *from test;+------+------+
| uid | name |
+------+------+
| 1 | bbbb |
+------+------+
1 row in set (0.00 sec)
此時(shí),在172.28.5.223上連接3307從庫(kù)
[root@push-5-223 ~]# mysql -uroot -p -S /var/lib/mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 6Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql>use test;
Reading table informationforcompletion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql> select *from test;+------+------+
| uid | name |
+------+------+
| 1 | bbbb |
+------+------+
1 row in set (0.00 sec)
數(shù)據(jù)同步成功。
同樣在172.28.5.223的3306和172.28.5.221的3307做主從配置
編輯172.28.5.223的3306配置文件
[root@push-5-223 ~]# vim /etc/mysql/my-3306.cnf
[mysqld]
# innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3306datadir=/home/mysql-5.7.26/data/3306socket=/var/lib/mysql/3306/mysql.sock
server_id=2233306log-bin=master-223binlog_format=row
#skip-grant-tables
symbolic-links=0pid-file=/var/run/mysqld/3306/mysqld.pid
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
[mysqld_safe]
log-error=/home/mysql-5.7.26/log/3306/mysqld.log
重啟3306實(shí)例
[root@push-5-223 ~]# mysqladmin -uroot -p -S /var/lib/mysql/3306/mysql.sock shutdown
Enter password:
[root@push-5-223 ~]# mysqld_safe --defaults-file=/etc/mysql/my-3306.cnf &[2] 10352[root@push-5-223 ~]# 2019-05-27T03:46:18.899652Z mysqld_safe Logging to '/home/mysql-5.7.26/log/3306/mysqld.log'.2019-05-27T03:46:18.965604Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data/3306
^C
[root@push-5-223 ~]# mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26-log MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> show variables like'%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2233306 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.01sec)
mysql>show master status \G*************************** 1. row ***************************File: master-223.000001Position:154Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:1 row in set (0.00 sec)
主庫(kù)啟動(dòng)成功
在172.28.5.221的3307配置文件
[root@push-5-221 ~]# vim /etc/mysql/my-3307.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# innodb_buffer_pool_size=128M
# join_buffer_size=128M
# sort_buffer_size=2M
# read_rnd_buffer_size=2M
user=mysql
port=3307datadir=/home/mysql-5.7.26/data/3307socket=/var/lib/mysql/3307/mysql.sock
server_id=2213307# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0log-error=/home/mysql-5.7.26/log/3307/mysqld.log
pid-file=/var/run/mysqld/3307/mysqld.pid
[myqld_safe]
log-error=/home/mysql-5.7.26/log/3307/mysqld.log
重啟3307實(shí)例
[root@push-5-221 ~]# mysqladmin -uroot -p -S /var/lib/mysql/3307/mysql.sock shutdown
[root@push-5-221 ~]# mysqld_safe --defaults-file=/etc/mysql/my-3307.cnf &[2] 6725[root@push-5-221 ~]# 2019-05-27T03:49:31.427996Z mysqld_safe Logging to '/home/mysql-5.7.26/log/3307/mysqld.log'.2019-05-27T03:49:31.482868Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data/3307
^C
[root@push-5-221 ~]# mysql -uroot -p -S /var/lib/mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionid is 2Server version:5.7.26MySQL Community Server (GPL)
Copyright (c)2000, 2019, 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 clearthe current input statement.
mysql> show variables like '%server_id%';+----------------+---------+
| Variable_name | Value |
+----------------+---------+
| server_id | 2213307 |
| server_id_bits | 32 |
+----------------+---------+
2 rows in set (0.01 sec)
執(zhí)行從庫(kù)命令
mysql>change master to-> master_host='172.28.5.223',-> master_port=3306,-> master_user='repl',-> master_password='Zaq1xsw@',-> master_log_file='master-223.000001',-> master_log_pos=154;
Query OK,0 rows affected, 2 warnings (0.42sec)
mysql>start slave;
Query OK,0 rows affected (0.06sec)
mysql>
測(cè)試數(shù)據(jù)
在172.28.5.223的3306創(chuàng)建test庫(kù)和test表,并插入一條記錄
mysql>create database test;
Query OK,1 row affected (0.06sec)
mysql>use test;
Database changed
mysql> create table test(id int,name varchar(10));
Query OK,0 rows affected (0.34sec)
mysql> insert into test values(1,'ccc');
Query OK,1 row affected (0.14sec)
mysql> select *from test;+------+------+
| id | name |
+------+------+
| 1 | ccc |
+------+------+
1 row in set (0.00 sec)
在172.28.5.221的3307上查看
sion for the right syntax to use near 'database' at line 1mysql>show databases;+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00sec)
mysql>use test;
Reading table informationforcompletion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql> select *from test;+------+------+
| id | name |
+------+------+
| 1 | ccc |
+------+------+
1 row in set (0.00 sec)
數(shù)據(jù)同步成功
至此3臺(tái)MYSQL服務(wù)器互為主從設(shè)置完畢。
四、多實(shí)例的啟動(dòng)和停止
停止3306實(shí)例: ?mysqladmin -uroot -p -S /var/lib/mysql/3307/mysql.sock shutdown
啟動(dòng)3306實(shí)例:?mysqld_safe --defaults-file=/etc/mysql/my-3306.cnf &
連接3306實(shí)例:mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock
總結(jié)
以上是生活随笔為你收集整理的mysql5.7 server id_三台mysql5.7服务器互作主从配置案例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql服务器多线程模型_mysql-
- 下一篇: mysql 经典问题_mysql经典排名