MySQL master configuration under Linux

Source: Internet
Author: User

MySQL server's master-slave configuration, which allows for read-write separation, or can be recovered from the standby library after the main library has been hung off
Need two machines, install MySQL, two machines in a connected LAN
Host a:192.168.1.100
Slave machine b:192.168.1.101
Can have more than one slave machine
1. Log in to host A first
Mysql>grant REPLICATION SLAVE on * * to ' backup ' @ ' 192.168.1.101 ' identified by ' 123456 ';
Given slave permissions, there are more than one cluster machine that executes multiple times
2. Open the my.cnf of host A, enter
Server-id = 1 #主机标示, integer log_bin =/var/log/mysql/mysql-bin.log #确保此文件可写 read-only =0 #主机, read and write can be binlog-do-db =test #需要备份数据, multiple lines binlog-ignore-db =mysql #不需要备份的数据库, more than one write multiple lines
3. Open the my.cnf from machine B, enter
Server-id = 2 Log_bin =/var/log/mysql/mysql-bin.log master-host =192.168.1.100 master-u Ser =backup master-pass =123456 master-port =3306 master-connect-retry=60 #如果从服务器发现主服务器断掉, reconnection time difference (seconds) Replicat E-do-db =test #只复制某个库 Replicate-ignore-db=mysql #不复制某个库
4. Synchronizing the database
Do not take too much trouble, only the master and slave libraries are started automatically synchronized, if not too troublesome, you can export the contents of the main library into SQL, and then run from the library again
5, restart the host a MySQL, and then restart from machine b MySQL
6. Verification
In host A, mysql>show master status\g;
In slave B, mysql>show slave status\g;
Can see roughly this content
file:mysql-bin.000001 position:1374 binlog_do_db:test Binlog_ignore_db:mysql
Can be in host A, do some insert, UPDATE, DELETE operation, see Host B, whether has been modified

MySQL master configuration under Linux

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.