Configuring the MySQL server to implement primary master replication

Source: Internet
Author: User

Statement

The Stars last night

Blog:http://yestreenstars.blog.51cto.com/

This article by oneself creation, if need reprint, please indicate source, thank cooperation!

Objective

Configure the MySQL server to implement primary master replication.

Experimental environment

Server 1 (hereinafter referred to as S1):

ip:192.168.1.88


Server 2 (hereinafter referred to as S2):

ip:192.168.1.89


Os:centos 6.2 32

mysql:5.1.73

Configuration

#  Stop the iptables firewall for S1 and S2 first. service iptables stop#  Modify the S1/etc/my.cnf file, add the following in the [Mysqld] field: log-bin= mysql-binlog-slave-updatesserver-id=1#  Similarly, modify the S2/etc/my.cnf file and add the following in the [Mysqld] field (note that Server-id cannot be the same): log-bin= mysql-binlog-slave-updatesserver-id=2#  Restart the Mysqld service for S1 and S2. service mysqld restart#  log in to the S2 database, execute the lock Table command, prevent someone from modifying the data while viewing the binary log file, and then execute the view command, recording the binary log file name and the current location. mysql> flush tables with read lock; query ok, 0 rows affected  (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+| file              | position | binlog_do_db | binlog_ ignore_db |+------------------+----------+--------------+------------------+| mysql-bin.000003  |      191 |               |                   |+------------------+----------+--------------+------------------+1 row in  set  (0.00 sec) #  log in to the S1 database, create a user for replication, and configure S2 as the primary replication server (readers are careful to modify the specific parameters according to the actual situation). mysql> grant replication slave on *.* to  ' slave ' @ ' 192.168.1.89 '   identified by  ' 123456 '; query ok, 0 rows affected  (0.00 sec) mysql> change master to  master_host= ' 192.168.1.89 ', master_user= ' slave ', master_password= ' 123456 ', master_log_file= ' Mysql-bin.000003 ', master_log_pos=191; query ok, 0 rows affected  (0.05 sec) #  the command to execute the lock table and view binary log file information on the S1 database. mysql> flush tables with read lock; query ok, 0 rows affected  (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+| file             |  position | binlog_do_db | binlog_ignore_db |+------------------+----------+---- ----------+------------------+| mysql-bin.000003 |      260 |               |                   |+------------------+----- -----+--------------+------------------+1 row in set  (0.00 sec) #  execute the Unlock table command in the S2 database, and create a user for replication and configure S1 as the primary replication server. mysql> unlock tables; query ok, 0 rows affected  (0.00 sec) mysql> grant replication  slave on *.* to  ' slave ' @ ' 192.168.1.88 '  identified by  ' 123456 '; query ok, 0 rows affected  (0.00 sec) Mysql> changE master to master_host= ' 192.168.1.88 ', master_user= ' slave ', master_password= ' 123456 ', Master_log_ File= ' mysql-bin.000003 ', master_log_pos=260; query ok, 0 rows affected  (0.03 SEC) #  performs the unlock table command on the S1 database and initiates replication. mysql> unlock tables; query ok, 0 rows affected  (0.00 sec) mysql> start slave; query ok, 0 rows affected  (0.00 sec) #  initiates replication in the S2 database. mysql> start slave; query ok, 0 rows affected  (0.00 SEC) #  Finally, execute show slave status; command to see if the configuration was successful, if both of the following are yes. slave_io_running: yesslave_sql_running: yes             #  readers can also verify that synchronization is done by creating databases and so on.


This article is from the "Last Night Stars" blog, please make sure to keep this source http://yestreenstars.blog.51cto.com/1836303/1568800

Configuring the MySQL server to implement primary master replication

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.