日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql5.7 server id_三台mysql5.7服务器互作主从配置案例

發布時間:2024/9/15 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql5.7 server id_三台mysql5.7服务器互作主从配置案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、架構

三臺msyql服務器221,222,223,每臺服務器開兩個實例,3306作為主庫,3307作為另外一臺服務器的從庫

二、每臺服務器安裝雙實例

參照:https://www.cnblogs.com/sky-cheng/p/10919447.html

進行雙實例安裝

三、每臺服務器的3306實例創建一個復制賬號

在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、首先設置好每個3306mysql實例的server_id參數為本機IP地址最后一位,3307實例server_id參數為本機IP地址最后一位再加端口號

在172.28.5.221服務器的3306配置文件中打開日志文件設置

[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 設置server_id

log-bin=master-221 設置log_bin日志文件名

binlog_format=row 指定日志格式為row

2、重啟3306實例,使配置生效

[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參數

mysql> show variables like '%server_id%';+----------------+---------+

| Variable_name | Value |

+----------------+---------+

| server_id | 2213306 |

| server_id_bits | 32 |

+----------------+---------+

2 rows in set (0.00 sec)

5、顯示主庫狀態

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

此時,需要記住上面的參數: ?File: master-221.000001 ??Position: 154 ,日志文件名和偏移量,需要在從庫上做主從設置時要用到這兩個參數

6、從庫設置

在172.28.5.222服務器上的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實例,使配置生效

[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、查看相應參數

[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、執行從庫命令

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、啟動從庫

mysql>start slave;

Query OK,0 rows affected (0.05 sec)

11、顯示從庫狀態

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

同步線程都已經啟動成功、

Exec_Master_Log_Pos: 154 同步主庫日志文件偏移量跟主庫的日志文件偏移量相同,說明已經完全同步

12、測試同步

在172.28.5.221上創建test庫和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)

此時,在172.28.5.222上連接從庫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)

已經跟主庫數據同步成功了。

同樣在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實例

[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

顯示主庫狀態

在172.28.5.223服務器上打開3307配置文件,將其設置為172.28.5.222的3306的從庫

[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

客戶端連接,設置從庫命令

[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)

啟動從庫

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:

此時,從庫已經啟動,并且同步線程啟動成功,同步完畢

測試數據

在172.28.5.222的3306上創建test庫個test表,并插入一條數據

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)

此時,在172.28.5.223上連接3307從庫

[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)

數據同步成功。

同樣在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實例

[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)

主庫啟動成功

在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實例

[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)

執行從庫命令

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>

測試數據

在172.28.5.223的3306創建test庫和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)

數據同步成功

至此3臺MYSQL服務器互為主從設置完畢。

四、多實例的啟動和停止

停止3306實例: ?mysqladmin -uroot -p -S /var/lib/mysql/3307/mysql.sock shutdown

啟動3306實例:?mysqld_safe --defaults-file=/etc/mysql/my-3306.cnf &

連接3306實例:mysql -uroot -p -S /var/lib/mysql/3306/mysql.sock

總結

以上是生活随笔為你收集整理的mysql5.7 server id_三台mysql5.7服务器互作主从配置案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。