mysql 8.0.28 主从配置
1. master
配置文件
#c:/dbm/m3300/my.ini
[mysqld]
port=3300
log-bin=mysql-bin
server-id=1
初始化、安装、启动
C:\dbm\m3300\bin>mysqld --initialize-insecure
C:\dbm\m3300\bin>mysqld --install m3300
Service successfully installed.
C:\dbm\m3300\bin>net start m3300
m3300 服务正在启动 ......
m3300 服务已经启动成功。
C:\dbm\m3300\bin>mysql -P3300 -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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 version();
+-----------+
| version() |
+-----------+
| 8.0.28 |
+-----------+
1 row in set (0.00 sec)
建立主从账号授权
alter user rep identified with mysql_native_password by '123';
必须使用mysql_natvie_password插件加密机制
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 157 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.04 sec)
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000002
Position: 157
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
mysql> create user rep identified by '123';
Query OK, 0 rows affected (0.26 sec)
mysql> grant replication slave on *.* to rep;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to rep;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 1071 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2. slave1
my.ini
[mysqld]
port=3301
log-bin=mysql-bin
server-id=2
初始化、安装、启动、查看信息
C:\dbm\m3301\bin>mysqld --initialize-insecure
C:\dbm\m3301\bin>mysqld --install m3301
Service successfully installed.
C:\dbm\m3301\bin>net start m3301
m3301 服务正在启动 .
m3301 服务已经启动成功。
C:\dbm\m3301\bin>mysql -uroot -P3301
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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 version();
+-----------+
| version() |
+-----------+
| 8.0.28 |
+-----------+
1 row in set (0.00 sec)
mysql> change master to master_host='127.0.0.1',
-> master_user='rep',
-> master_password='123',
-> master_log_file=' mysql-bin.000002',
-> master_log_pos=1071;
Query OK, 0 rows affected, 7 warnings (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Connecting to source
Master_Host: 127.0.0.1
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1071
Relay_Log_File: MS-UXUYPZYCFGQB-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Connecting
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: 1071
Relay_Log_Space: 157
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: 2003
Last_IO_Error: error connecting to master 'rep@127.0.0.1:3306' - retry-time: 60 retries: 1 message: Can't connect to MySQL server on '127.0.0.1:3306' (10061)
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 220219 11:41:59
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:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)
3. slave2
[mysqld]
port=3302
log-bin=mysql-bin
server-id=3
C:\dbm\m3302\bin>mysqld --initialize-insecure
C:\dbm\m3302\bin>mysqld --install m3302
Service successfully installed.
C:\dbm\m3302\bin>net start m3302
m3302 服务正在启动 .
m3302 服务已经启动成功。
C:\dbm\m3302\bin>mysql -uroot -P3302
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> change master to master_host='127.0.0.1',
-> master_user='rep',
-> master_password='123',
-> master_port=3300,
-> master_log_file='mysql-bin.000002',
-> master_log_pos=5264;
Query OK, 0 rows affected, 8 warnings (0.12 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 127.0.0.1
Master_User: rep
Master_Port: 3300
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 5443
Relay_Log_File: MS-UXUYPZYCFGQB-relay-bin.000002
Relay_Log_Pos: 505
Relay_Master_Log_File: mysql-bin.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: 5443
Relay_Log_Space: 725
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: c8414953-9133-11ec-a320-1c3947e43531
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica 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:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> use db;
Database changed
mysql> show tables;
Empty set (0.01 sec)
mysql> show tables;
+--------------+
| Tables_in_db |
+--------------+
| t |
+--------------+
1 row in set (0.00 sec)
从机上执行
change
start slave
stop slave
change master to master_host='127.0.0.1', master_user='rep', master_password='123', master_port=3300, master_log_file='mysql-bin.000002', master_log_pos=5264;