mysq5.7 主主同步
生活随笔
收集整理的這篇文章主要介紹了
mysq5.7 主主同步
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
db01??172.21.0.10
db02??172.21.0.14
一、安裝數據庫看上一遍博客
修改配置文件??db01??172.21.0.10
[root@VM_0_10_centos mysql]# cat /etc/my.cnf [mysqld] port=3306 character-set-server=utf8 basedir=/usr/local/mysql datadir=/usr/local/mysql/data #innodb_buffer_pool_size=8M max_connections=1000 slow_query_log = 1 slow_query_log_file=/usr/local/mysql/log/mysql_slow_query.log long_query_time = 5 max_connections=1000log-bin=/usr/local/mysql/log_bin/mysql-bin.log # 開啟二進制日志 binlog_format=mixed server-id = 1 auto_increment_increment=2 # 步進值auto_imcrement。一般有n臺主 MySQL 就填n auto_increment_offset=1 # 起始值。一般填第n臺主MySQL。此時為第一臺主MySQL replicate-do-db=schneider # 要同步的數據庫,默認所有庫 expire_logs_days=180 #binlog過期清理時間 max_binlog_size=512m #binlog每個日志文件大小 replicate-do-db=schneider # 要同步的數據庫,默認所有庫[mysqld_safe]log-error=/usr/local/mysql/data/error.logpid-file=/usr/local/mysql/data/mysql.pidtmpdir=/usr/local/mysql/tmp[client] default-character-set=utf8 [mysql] default-character-set=utf8修改配置文件??db01??172.21.0.14
[root@VM_0_14_centos log_bin]# cat /etc/my.cnf [mysqld] port=3306 character-set-server=utf8 basedir=/usr/local/mysql datadir=/usr/local/mysql/data #innodb_buffer_pool_size=8M max_connections=1000 slow_query_log = 1 slow_query_log_file=/usr/local/mysql/log/mysql_slow_query.log long_query_time = 5 max_connections=1000log-bin=/usr/local/mysql/log_bin/mysql-bin.log # 開啟二進制日志 binlog_format=mixed server-id = 2 #id 不能一樣 auto_increment_increment=2 # 步進值auto_imcrement。一般有n臺主 MySQL 就填n auto_increment_offset=2 # 起始值。一般填第n臺主MySQL。此時為第一臺主MySQL replicate-do-db=schneider # 要同步的數據庫,默認所有庫 expire_logs_days=180 #binlog過期清理時間 max_binlog_size=512m #binlog每個日志文件大小 replicate-do-db=schneider # 要同步的數據庫,默認所有庫[mysqld_safe]log-error=/usr/local/mysql/data/error.logpid-file=/usr/local/mysql/data/mysql.pidtmpdir=/usr/local/mysql/tmp[client] default-character-set=utf8 [mysql] default-character-set=utf8?二、互換主從 注意需要鎖表 或者停庫
db01??172.21.0.10
# 創建用戶 并授權CREATE USER 'mysq114'@'172.21.0.14' IDENTIFIED BY '123456';GRANT REPLICATION SLAVE ON *.* TO 'mysq114'@'172.21.0.14' IDENTIFIED BY '123456'; FLUSH PRIVILEGES;mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)# 告訴bin-log位置? 在db02??172.21.0.14 執行
CHANGE MASTER TO MASTER_HOST='172.21.0.10', MASTER_USER='mysq114', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS= 154;db02??172.21.0.14
CREATE USER 'mysql10'@'172.21.0.10' IDENTIFIED BY '123456';GRANT REPLICATION SLAVE ON *.* TO 'mysql10'@'172.21.0.10' IDENTIFIED BY '123456';FLUSH PRIVILEGES;mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000002 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)# 告訴bin-log位置? 在db01??172.21.0.10 執行
CHANGE MASTER TO MASTER_HOST='172.21.0.14', MASTER_USER='mysql10', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS= 154;?三、查看結果
db1 和db2 都執行start slave;db01??172.21.0.10
mysql> show slave status\G *************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 172.21.0.14Master_User: mysql10Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 474Relay_Log_File: VM_0_10_centos-relay-bin.000006Relay_Log_Pos: 687Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: schneiderReplicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 474Relay_Log_Space: 1069Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2Master_UUID: 9e57cecc-d148-11e9-92db-5254007bbb3cMaster_Info_File: /data/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)db02??172.21.0.14
mysql> show slave status\G *************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 172.21.0.10Master_User: mysq114Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 355Relay_Log_File: VM_0_14_centos-relay-bin.000005Relay_Log_Pos: 568Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: schneiderReplicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 355Relay_Log_Space: 950Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: 9a3346c4-d148-11e9-a4f1-525400857720Master_Info_File: /data/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)四、最后測試是否同步
?
轉載于:https://www.cnblogs.com/zhaojingyu/p/11482065.html
總結
以上是生活随笔為你收集整理的mysq5.7 主主同步的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vCenter线上操作磁盘扩容
- 下一篇: 开发工具:Git 代码回退功能详解,很实