Configure master-slave backup for MySQL

Source: Internet
Author: User

For data security, data in the database is generally backed up. MySQL comes with master-slave backup, which is very convenient to use and has powerful functions and can provide approximate synchronization performance.

When configuring master-slave backup, you only need to let slave know the master'sAddressAndPort, And a permission to back up replication slaveAccountThe master does not need to know slave-related information.

MASTER: 192.168.1.123: 3306

First, configure the master. For Linux, the MySQL configuration file is generally/Etc/MySQL/My. CNFFor WindowsInstallMy. ini under the Directory

Add the following in the configuration file:Code(In some cases, this content may exist in the configuration file. You only need to remove the comment ):

Server-id = 1

Log-bin =/var/log/MySQL/mysql-bin.log

Binlog_do_db = XXXXX # database to be backed up

The configuration in slave is as follows:

Server-id = 2 # As long as it is larger than 1, 1 stands for Master

Master-host = 192.168.1.123

Master-Port = 3306

Master-user = iuser

Master-Password = useri

Master-connect-retry = 60 # If the connection fails, try it 60 seconds.

Replicate-do-DB = XXXX # the database to be backed up. The structure must be the same as that in the master.

Note:

Grant replication slave permission to iuser in master

Master>Grant replication slave on *. * To iuser @ '%' identified by 'useri ';

Replace iuser with the corresponding user name and useri with the corresponding password.

After the configuration is complete, first restart the Master, then restart the slave, and execute

Slave>Start slave;

In the master, you can view the status through show Master status, and in the slave, you can view the status through show slave status.


Test:

After inserting a record in the master table, you will soon be able to see the same data in the corresponding slave table. If there is no synchronization, you can view the error log to find the specific cause,

The error log in Windows is in the data directory of the installation directory, which is generally the *. Err file;

In Linux, the error log is usually stored in/var/log/MySQL/error. log.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.