use tools
MySQL data version: 5.6.36-log,
two cloud servers (Linux system)
First of all, it needs to be installed under the Linux system MySQL
, the specific steps can be referred to here , and ensure that the two hosts can access each other, you can ping directly.
Configure Master
- In the
Linux
environment,MySQL
the configuration file is in/ect/my.cnf
, open and edit the file directly:vim /etc/my.cnf
[mysqld]
Enter configuration under
log-bin=mysql-bin
server-id=2
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-do-db=rwtest
The one here is server-id
used to identify the unique database, here it is set to 2, and the slave library needs to be set to other values .
binlog-ignore-db
: Indicates the database to ignore when synchronizing
binlog-do-db
: Specify the database that needs to be synchronized
- Reboot
MySQL
:service mysqld restart
- Log
MySQL
in and authorize access users: Slave machines requireFile
permissions andREPLICATION SLAVE
permissions, and of course full permissions can be granted.
grant file on *.* to 'root'@'%' identified by 'your password';
grant replication slave on *.* to 'root'@'%' identified by 'your password';
flush privileges;
or
grant all privileges on *.* to 'root'@'%' identified by 'your password';
flush privileges;
- After completion, you can view
Master
the status below:show master status
mysql> show master status;
+------------------+----------+--------------+----------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000001 | 2272 | rwtest | information_schema,mysql | |
+------------------+----------+--------------+----------------------------------+-------------------+
1 row in set (0.03 sec)
Both here File
and Position
in Slave
are used, Binlog_Do_DB
referring to the database that needs to be synchronized, referring to the database Binlog_Ignore_DB
that does not need to be synchronized, which is the value just configured.
Configure Slave
- Also write the configuration file under [mysqld]
log-bin=mysql-bin
server-id=3
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
replicate-do-db=rwtest
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60
- After the configuration is complete, restart it
MySQL
and enter the settings corresponding to it.Master
mysql> stop slave; #关闭Slave
mysql> change master to master_host='Master主机IP',master_user='刚才授权的用户',master_password='your password',master_log_file='mysql-bin.000001', master_log_pos=2272;
mysql> start slave; #开启Slave
master_log_file
and master_log_pos
are the status values of the Master. must correspond .
- Log in to the slave database and check the status of the slave:
show slave status \G
Slave_IO_State: Waiting for master to send event
Master_Host: 你的Master主机IP
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2272
Relay_Log_File: izwz9fcvpu481xh55cegx0z-relay-bin.000002
Relay_Log_Pos: 1339
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: rwtest
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: 2272
Relay_Log_Space: 1530
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
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: 2
Master_UUID: de20814f-2fb8-11e7-8f61-5254002b91a1
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.03 sec)
If there is no Error reported in the status, it means that the configuration is successful.
Next, you connect the two databases through a visual tool, and perform additions, deletions and modifications in the main library, and there will be corresponding operations in the slave library, but such operations in the slave library are invalid for the main library.