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