mysql database master-slave synchronization interactive configuration step, a paper mysql multiple database instances 3306 and 3307 are configure, 3306 based libraries, 3307 from the library (more than a single instance of a multi-instance configuration is the same)
A .my.cnf file configuration
1. Modify the my.cnf configuration file, the primary database 3306 to open the log-bin , Server-ID is not the same
[root@mysql ~]# egrep"log-bin|server-id" /data/{3306,3307}/my.cnf
/data/3306/my.cnf:log-bin=/data/3306/mysql-bin
/data/3306/my.cnf:server-id=1
/data/3307/my.cnf:#log-bin=/data/3307/mysql-bin
/data/3307/my.cnf:server-id=3
2. Restart the database 3306 and 3307
[root@mysql ~]#/data/3306/mysql stop
[root@mysql ~]#/data/3306/mysql start
[root@mysql ~]#/data/3307/mysql stop
[root@mysql ~]#/data/3307/mysql start
3. Go to the main database 3306 , the query log_bin is open, server_id how much
[root@mysql ~]# mysql -uroot-p123456 -S /data/3306/mysql.sock
mysql> show variables like"log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.01 sec)
mysql> show variables like"server_id";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.00 sec)
4. Create a database designed to synchronize user
mysql> grant replicationslave on *.* to rep@'10.0.0.%' identified by '123456';
### * * on behalf of all the libraries and all the tables
mysql> flush privileges;
mysql> select user,hostmysql.user;
mysql> show grants forrep@'10.0.0.%';
II. Main Library 3306 Backup
mysql> flush table with readlock; // lock table, in this case, read-only, can not write, this time mysql window can not quit, quit the lock table will fail, beyond the default time will automatically unlock the lock table
mysql> show variables like'timeout% '; // view the default lock time table
mysql> show master status; // Check binlog position
+------------------+----------+--------------+------------------+-----------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+-----------------------------------+
| mysql-bin.000004 | 328| | |
+------------------+----------+--------------+------------------+-----------------------------------+
1 row in set (0.00 sec)
[root @ mysql ~] # mysqldump -uroot -p123456 -S /data/3306/mysql.sock -A -B | gzip> / opt / bak _ $ (date +% F) .sql.gz // re-open a CRT window for backup
[root@mysql ~]# ls /opt
bak_2017-06-28.sql.gz
mysql> show master status; // backup data, again see binlog position, confirmed that no new data is written during this period
mysql> unlock tables; // unlock
III. 3306 to restore the main repository of data to back out from the library 3307
1. Log in 3307 , confirmed logbin is turned off, Server the above mentioned id and 3306 do not conflict
[root@mysql ~]# mysql -uroot-p123456 -S /data/3307/mysql.sock
mysql> show variables like"log_bin";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | OFF |
+---------------+-------+
1 row in set (0.01 sec)
mysql> show variables like"server_id";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 3 |
+---------------+-------+
1 row in set (0.00 sec)
2. 3306 backed up data to restore 3307 on
[root@mysql ~]# cd /opt
[root@mysql opt]# ls
bak_2017-06-28.sql.gz
[root@mysql opt]# gzip -dbak_2017-06-28.sql.gz
[root@mysql opt]# ls
bak_2017-06-28.sql
[root@mysql opt]# mysql -uroot-p123456 -S /data/3307/mysql.sock <bak_2017-06-28.sql
3. landing 3307 , execute the following command, connecting the main library 3306
[root@mysql opt]# mysql -uroot-p123456 -S /data/3307/mysql.sock
mysql> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.20',
-> MASTER_PORT=3306,
-> MASTER_USER='rep',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-bin.000004',
-> MASTER_LOG_POS=328;
mysql> start slave; // from the library 3307 turn on the main switch from replication
mysql> show slave status \ G // check the synchronization status
*************************** 1.row ***************************
Slave_IO_State: Waiting formaster to send event
Master_Host: 10.0.0.20
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 328
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes // confirm these two is yes state
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 328
Relay_Log_Space: 403
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0 // number of seconds from the library during the delay than the main library copy
Master_SSL_Verify_Server_Cert:No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)
Such checking or synchronization status
[root @ mysql ~] # mysql -uroot-p123456 -S /data/3307/mysql.sock -e "show slave status \ G" | egrep -i "running | _behind" // - e action is not required landing mysql interactive typing the command
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
View thread state
[root@mysql ~]# mysql -uroot -p123456 -S/data/3307/mysql.sock -e "show processlist\G"
[root@mysql ~]# mysql -uroot -p123456 -S/data/3306/mysql.sock -e "show processl
IV. Test
In the main library 3306 to create the database, and then log in 3307 to see whether the normal synchronization, the test has been properly synchronized ^ _ ^