centos 7.0
mysql5.6 (yum package yum localinstall mysql-yum)
# vi /etc/my.cnf
[ mysqld]
log-bin=mysql-bin //[have to]Enable binary log
server-id=232//[have to]The unique ID of the server, the default is 1, usually the last segment of the IP
# vi /etc/my.cnf
[ mysqld]
log-bin=mysql-bin //[Not required]Enable binary log
server-id=222//[have to]The unique ID of the server, the default is 1, usually the last segment of the IP
service mysqld restart
//If the startup is not successful,View log, usually my.cnf configuration problem
cat /var/log/mysqld.log
GRANT REPLICATION SLAVE ON *.* to 'hs'@'%' identified by 'a123.+-';//Generally, the root account is not required,@;%;Means that all clients can connect, as long as the account and password are correct, the specific client IP can be used instead, such as 192.168.0.1. Strengthen safety.
mysql>show master status;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000003|712|||+------------------+----------+--------------+------------------+1 row inset(0.00 sec)//Note: Do not operate the main server MYSQL after performing this step to prevent the main server status value from changing
mysql>change master to master_host='192.168.0.232',master_user='hs',master_password='a123.+-',master_log_file='mysql-bin.000003',master_log_pos=712;
Mysql>start slave;//Start copy function from server
mysql> show slave status\G
Slave_IO_State: Waiting for master to send event
Master_Host:192.168.0.232//Primary server address
Master_User: hs //Authorized account name, try to avoid using root
Master_Port:3306//Database port, some versions do not have this line
Connect_Retry:60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos:600//#Synchronously read the location of the binary log, greater than or equal to Exec_Master_Log_Pos
Relay_Log_File: ddte-relay-bin.000003
Relay_Log_Pos:251
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes //This status must be YES
Slave_SQL_Running: Yes //This status must be YES......//Note: Slave_IO and Slave_The SQL process must run normally, that is, the YES state, otherwise it is an error state(Such as: one of the NO is an error)。
The above operation process, the master-slave server configuration is completed. The following is to build a library to insert data to test
Recommended Posts