Get the App
SLTechnology News&Howtos  ›  Database  › 

How to complete the MySQL master-slave hot backup in linux?

Shulou Source: shulou.com Published: 2022-06-01 05:15:41 10月01日 Update

With the advent of the era of big data, data is particularly important. The loss or destruction of data can even destroy a company.

The master-slave hot backup under Linux is actually very simple.

1. As the primary server Master, it records every change in its binary log Binarylog. (it is the responsibility of the server to read the log and then execute it again at your own place. ) 2. As a slave server Slave, it logs in to master with the account on master, reads master's Binarylog, writes to its own relay log Relaylog, and then its own SQL thread reads the relay log and executes it again. At this point, the changes on the master server are synchronized to the slave server. The following specific configuration methods are described below: master and slave means that there are no less than two servers. Here, 192.168.0.1 (master server database) 192.168.0.2 (slave server database) is taken as an example:

Master server master configuration [mysqld]

Datadir=/var/lib/mysql

Socket=/var/lib/mysql/mysql.sock

User=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

Symbolic-links=0 server-id=1

Log-bin=mysql-bin

Relay-log=relay-bin

Relay-log-index=relay-bin-index [mysqld_safe]

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

Configure currency symbols from server Slave

[mysqld]

Datadir=/var/lib/mysql

Socket=/var/lib/mysql/mysql.sock

User=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

Symbolic-links=0

Server-id=2 # cannot be the same as the primary server

Log-bin=mysql-bin

Replicate-do-db=test # Select a hot backup database

Log-slave-updates=1 [mysqld_safe]

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

When the configuration is complete, login Slave, and then execute the following command: mysql > stop slave

Mysql > change master to master_host='192.168.0.1',master_user='root',master_password='123456'

# configuration of the master database

Mysql > start slave

Mysql > show slave status\ G

Financial question and answer http://www.gendan5.com/topic/businessnews.html

Check whether the relevant configuration is working properly: yes is normal.

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

If either of the above two configurations is No. The hot standby cannot be carried out normally, and the specific reasons need to be checked.

Finally, when the test does anything in the test library of the master data, the test in the database of the slave server will be synchronized to this point, and the Linux master-slave hot backup data will be completed.

Tags: Server service data configuration database master-slave log two relay synchronization check important binary company reason command especially method time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple macOS Microsoft Shulou Information