Mysql database master-slave synchronization (replication) hot backup

With the development of big data, data security issues become increasingly prominent, it is often not taken seriously database maintenance becomes essential, disaster recovery data into a major business / personal business owners must pay attention to the operation of the link. The article mentions several options for automated backup and disaster prevention, just to practice what today master / bi-directional offsite backup solution from heat.

Mysql database synchronization (copy) the concept of master-slave synchronization so that data can be copied to seamlessly migrate from one server to another server. This process, a server acts as the master server (master), the other acting as a slave or a plurality of additional server (slave). The replication process I / O is asynchronous, so the server does not need to remain associated state.

Mysql database synchronization from the master in reality is widely used, for example, well-known off-site disaster recovery, load balancing, improve database performance, data security, etc., to protect the source to use both primary Mysql database from the synchronization.

The primary server (master) to change its data recorded in a manner to nodes in a binary log from the server (slave) of the I / O thread through a main authorization server node account query log, the log is written to the relay itself, SQL thread reads the relay node change data with its own log database log contrast, if the main server (master) to change the follow-up reproduction itself performs writing its own database, if the node does not change into hibernation, wait change the primary server (master) data nodes.

master primary server: 45.32.250.228

slave from the server: 108.160.131.26

System environment must be the same two servers, database version must be the same, here I used the version of Mysql 5.7, this version in the head or the mainstream version of the database server, very practical.

Modify the master server (master) database configuration file my.cnf, the file path is generally /etc/my.cnf

Practical vi /etc/my.cnf in which the main server (master) database configuration file, add the following code:

log-bin = mysql-bin is turned binary log, server-id = 1 as a server unique ID, unique non-repeating, binlog-do-db need synchronization (replicate) database name, binlog-ignore-db = nosql synchronization (copy) out of the negative server, log-bin = / var / lib / mysql / binlog log file is specified, if the primary data server fails to start, by cat /var/log/mysqld.log | tail -30 See mysql failed to start a log, look for solutions from the contents of the log, log-slave-updates = YES synchronization after log from the server.

Once configured service mysqld restart restart mysqld process.

Add to authorize account linking primary database server, user name: master password: master-password

108.160.131.26 allow the server access.

? REPLICATION SLAVE privilege is: to make a response from the server (slave) database requests.

Mysql command to log in through the master server (master) database as root, mysql -uroot -p, enter a password to log database server, execute SHOW MASTER STATUS??;

We can see you want to use the binary file mysql-bin.000003, location data node 73, testsql specified database synchronization, database synchronization excluded nosql.

Configuration process kinds? Binlog_Do_DB and Binlog_Ignore_DB we basically just need to choose one on it.

Also you need to modify the database server configuration file vi? /Etc/my.cnf, add the following code

server-id = 2 represents the server from the server id salve, and unique to be noted that, replicate-do-db requiring data synchronization, replicate-ignore-db = nosql excluded database synchronization.

Log master server (master) database as root via the command mysql, mysql -uroot -p, enter a password to log database server, into the main server to provide authorized account for the slave account

Here we use the authorized account master primary server, the binary file mysql-bin.000003, data node number 73.

Then execute show slave status \ G; see the synchronization status

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Both correctly represent the complete docking database synchronization (replication) thread is working, Waitin for master to send event ... said it is waiting for data from the main database update master database slave.

I have a database master-slave synchronization configuration according to become, out of curiosity, I will come again the main upside from this configuration actually found to form a dual master server and heat simultaneously, so you can modify that two need to have permission to create a business efficient environment.

Master-slave synchronization can take advantage of the characteristics from more than one principal, we can also use a combination of various forms of a variety of database architecture, business operations so as to achieve a more efficient and safe results.

Reference article: https: //blog.csdn.net/hguisu/article/details/7325124

 

Guess you like

Origin www.cnblogs.com/mynale/p/11018503.html