Write directory title here
- foreword
- The first chapter finds the virtual machine corresponding to the master database and the slave database
- Chapter 2 Start Master-Slave Replication
-
- 2.1 SHOW SLAVE STATUS\G;
- 2.2 Slave_IO_Running: No
- 2.3 Solutions
-
- 2.3.1 Enter the input in the slave and stop the synchronization from the library:
- 2.3.2 Enter the input in the master and clear the log
- 2.3.3 Enter the input in the master and record the status information
- After 2.3.4, enter the slave library configuration, do not touch the main library
- 2.3.5 Testing
- 2.3.6 There is no data from the beginning of the library
- 2.7 After the test, it is verified that there is indeed one more piece of data
- Chapter 3 Verification of the main library
foreword
This is actually a project built a long time ago. When I moved in May, the interviewer asked me which advanced features of the database I know, and whether I have done cluster deployment. I said that I have not done it, but just built a distributed , and then there is the master-slave architecture in the distribution. But at this time, it involves some principle issues in the master-slave architecture.
Let's first consider the one-master-one-slave architecture
This article is not a construction process from 0 to 1, but a practice version from 1 to 1.01. If you want to build it, you can watch Master Kong's explanation on the Xiaopo website.
The first chapter finds the virtual machine corresponding to the master database and the slave database
1.1 Check the corresponding virtual machine IP
At the time of configuration, there were too many virtual machines, and it was impossible to tell which of these virtual machines was which.
As shown in the figure above, too many links were built.
To determine whether the database is installed:
1.2 rpm to find out whether the database is installed
rpm -qa | grep mysql
Check out this result
[root@centos121 ~]# rpm -qa | grep mysql
mysql-community-client-plugins-8.0.25-1.el7.x86_64
mysql-community-client-8.0.25-1.el7.x86_64
mysql-community-common-8.0.25-1.el7.x86_64
mysql-community-libs-8.0.25-1.el7.x86_64
mysql-community-server-8.0.25-1.el7.x86_64
1.3 Find detailed database configuration information
This step needs to determine which
final solution is vim my.cnf
to look at the configuration information one by one, because I was configuring it according to Master Kong’s Mysql in Shang Silicon Valley, and
at the same time look at the initial reference configuration document
The characteristics of the master node are as shown
in the figure below. In the slave node, my.cnf is like this.
Write down the IP addresses of these two devices
主:192.168.80.121
从:192.168.80.120
Chapter 2 Start Master-Slave Replication
The startup was not very smooth, and it was hard to find the main library and the slave library. As a result, I couldn’t find it.
2.1 SHOW SLAVE STATUS\G;
The title sentence is actually problematic, the crux of the problem is that this ;
symbol cannot be added
ERROR:
No query specified
2.2 Slave_IO_Running: No
This error is specifically like this, similar to a problem with reading binary log, in the slave database, it will report 1236 error.
Last_IO_Error: Got fatal error 1236 from master解决方法
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
Last_SQL_Errno: 0
The master-slave library is out of sync due to clearing data
2.3 Solutions
2.3.1 Enter the input in the slave and stop the synchronization from the library:
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
2.3.2 Enter the input in the master and clear the log
mysql> flush logs;
Query OK, 0 rows affected (0.02 sec)
2.3.3 Enter the input in the master and record the status information
mysql> show master status;
+----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+------------------+-------------------+
| xyt-bin.000005 | 156 | | | |
+----------------+----------+--------------+------------------+-------------------+
After 2.3.4, enter the slave library configuration, do not touch the main library
mysql> CHANGE MASTER TO MASTER_LOG_FILE='xyt-bin.000005',MASTER_LOG_POS=156;
Query OK, 0 rows affected, 3 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.80.121
Master_User: slave1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: xyt-bin.000005
Read_Master_Log_Pos: 156
Relay_Log_File: centos121-slave-relay-bin.000002
Relay_Log_Pos: 322
Relay_Master_Log_File: xyt-bin.000005
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: 156
Relay_Log_Space: 541
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: d2f34f1e-df67-11ed-bf42-000c29229240
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave 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.00 sec)
2.3.5 Testing
2.3.6 There is no data from the beginning of the library
2.7 After the test, it is verified that there is indeed one more piece of data
Chapter 3 Verification of the main library
121 is indeed the master node,
the secondary verification configuration is complete