MySQL Master-slave configuration

Source: Internet
Author: User

1: Environment two MySQL server master (mysql): 192.168.1.100

From (MySQL): 192.168.1.200 Note: Both MySQL versions must be consistent

2: Configure the primary server Mysqld configuration

Vi/etc/my.cnf

Server-id=100 #设置主服务器的ID (the last one to write the IP of the primary server)

innodb_flush_log_at_trx_commit=2

Sync_binlog=1 #开启binlog日志同步功能

log-bin=mysql-bin-100 #binlog日志文件名

Binlog-do-db=xxxx #表示同步某个数据库 (This is omitted if synchronization is all)

Restart master MySQL after configuration

Service mysqld Restart

Login Database

Mysql-u root-p

Mysql>grant replication Slave on * * to ' lk ' @ ' 192.168.1.200 ' identified by ' 01234567 '; #授权给从数据库: 192.168.1.200 account: LK Password: 01234567

Mysql>show master status; #查看库状态 records the values of File and position to be provisioned from the server


3: Configure from MySQL server

Vi/etc/my.cnf

server-id=200

innodb_flush_log_at_trx_commit=2

Sync_binlog=1

log-bin=mysql-bin-200

Save restart MySQL Service

Log in to MySQL

Mysql-u root-p

Mysql>change Master to master_host= ' 192.168.1.100 ', master_user= ' lk ', master_password= ' 01234567 ', master_log_file = ' mysql-bin-100.000001 ', master_log_pos=240

Mysql>start slave; #开启从库

mysql>show slave status; #出现 Slave_io_running:yes and Slave_sql_running:yes are successful.

You can also create a library on the main library to refresh from the library to see if synchronization is not.


This article is from the "Code slave" blog, please be sure to keep this source http://fwy9110.blog.51cto.com/9843077/1919680

MySQL Master-slave configuration

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.