Master-slave replication settings for Mysql in LINUX

Source: Internet
Author: User
For two servers, the intranet IP address of A is 192.168.1.111, the intranet IP address of B is 192.168.1.222, A is the master, and B is the Mysql (1) vim/etc/mysql/my configured for Slave1. cnf remove server_id1 and log_bin/var/log/mysql/mysql-bin.log in the [mysqld] Segment # two servers, A's intranet IP address is 192.168.1.111, B's intranet IP address is 192.168.1.222, A as the master, B as the Slave

1. configure Mysql of

(1) vim/etc/ Mysql/My. cnf
Remove the # Comment for server_id = 1 and log_bin =/var/log/mysql/mysql-bin.log in the [mysqld] segment
Binlog-do-db = s3 s3 is the name of the database to be synchronized. if this row does not exist, all data is synchronized, and binlog_ignore_db = mysql. The name of the database to ignore synchronization is mysql. if there are multiple data to be synchronized or ignored, configure multiple rows and save and exit.

(2) create a copy account (name: repl, allow remote connection, password: 123456 ):
Grant replication slave, RELOAD, SUPER, NO *. * TO repl @ '%' identified by '123 ';
Flush privileges;

(3) restart the mysql service or directly reboot the machine.

(4) enter mysql, and then use show master status \ G to view the status of the binary log. The result is similar to the following:
+ ------------------ + ---------- + -------------- + ------------------ + | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------------ + ---------- + -------------- + ------------------ +
| Mysql-bin.000003 | 1376 | s3 |
+ ------------------ + ---------- + -------------- + ------------------ +


2. configure Mysql of B

(1) vim/etc/mysql/my. cnf
Remove the # comment of server_id = 1 and log_bin =/var/log/mysql/mysql-bin.log in the [mysqld] segment and change server_id to 2, which is different from the master machine. Add the following content:
Binlog_do_db = s3
Log-slave-updates
Save and exit

(2) restart the mysql service

(3) go to mysql and run
Change master TOMASTER_HOST = '192. 168.1.111 ', MASTER_USER = 'repl', Master_Port = 192, MASTER_PASSWORD = '000000', MASTER_LOG_FILE = 'MySQL-bin.000003', MASTER_LOG_POS = 3306;
Slave start;
Note that in the above CHANGE statement, MASTER_LOG_FILE and MASTER_LOG_POS are the results of the show masterstatus command mentioned in 1.4 above, specifying the binary file name and the location where synchronization starts.

(4) view the SLAVE status: show slave status \ G
* *************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.111
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 1376
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 1355
Relay_Master_Log_File: mysql-bin.000003
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: 1376
Relay_Log_Space: 1512
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

If the two red lines above are YES, the connection is normal and can be copied.

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.