CentOS6.8 MySQL 5.6 implements master-slave replication, centos6.8mysql

Source: Internet
Author: User

CentOS6.8 MySQL 5.6 implements master-slave replication, centos6.8mysql

Master database operations

1. Add the mysqldump command to/usr/bin.

1 ln -s /application/mysql/bin/mysqldump /usr/bin/

2. Enable the log-bin function on the master.

1 # vim /etc/my.cnf
log_bin=mysql-binserver_id =1

3. Restart mysql

1 # /etc/init.d/mysqld restart

4. log onto mysql to create an account on the master server and authorize the slave function.

1 #mysql –uroot –p2 mysql> grant replication slave on *.* to 'repl'@'%' identified by 'repl';3 mysql> flush priviliges;4 mysql> flush tables with read lock;

5. Use the mysqldump command to back up the database of the master server

1 # mysqldump -uroot -p -A  --master-data=1 > /tmp/master_16-09-12.sql

6. After the backup is complete, restore the write operation.

1 mysql> unlock tables;

Slave database operations

1. Stop the slave synchronization operation

1 mysql> stop slave;

2. modify the configuration file of the slave Database

1 # vim /etc/my.cnf
log_bin=mysql-binserver_id = 2

3. Import the master_16-09-12. SQL file to the slave Database

1 # mysql -uroot -p < master_16-09-12.sql

4. Configure the slave server slave

1 mysql> change master to 2 master_host="192.168.92.137",3 master_user="repl",4 master_password="repl";

5. Start the slave server slave

1 mysql> start slave;

6. Check the slave server status

1 mysql> show slave status\G;

Note: Only when Slave_IO_Running and Slave_ SQL _Running both succeed. If the master-slave synchronization is successful, no verification is performed. You can perform an experiment on your own.

 

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.