System environment: centos6.7 MySQL
Master ip:192.168.16.110
Slave ip:192.168.16.12
Primary server
1.vim/etc/my.cnf
Append the following content:
[Mysqld]
Log-bin=test-log #启用二进制文件
server-id=110 #服务器编号
2. Restart the mysqld of the primary service and turn off the firewall
Server mysqld Restart
Server Iptables Stop
3. Add users who can connect from the server
Mysql-uroot-p
Create user ' slave ' @ ' 192.168.16.12 ' identified by ' slave ';
Grant Replication Slave on * * to ' slave ' @ ' 192.168.16.12 ';
Exit
4. Get the primary server binary log information
Mysql-uroot-p
Flush tables with read lock;
Show master status;
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 3550020 | | |
+------------------+----------+--------------+------------------+
Unlock tables;
From the configuration:
Vim/etc/my.cnf
Append the following content:
[Mysqld]
Server-id=12 #服务器编号
2. Restart the mysqld of the primary service and turn off the firewall
Server mysqld Restart
Server Iptables Stop
3. Connecting the master server configuration
Mysql-u root-p
Change Master to master_host= ' 192.168.16.110 ',
Master_user= ' slave ',
master_password= ' slave ',
Master_log_file= ' mysql-bin.000009 ',
master_log_pos=3550020;
Start slave;
Show Slave Status\g
Data Synchronization Verification:
Create Database test2;
User Test2
CREATE TABLE T_table (
Name Char (20),
Age int,
Note varchar (50));
INSERT INTO t_table values
(' Rocky ', ' A ', ' Shanghai ');
Exit
MySQL Master-slave configuration