MySql的Master/Slave
主庫配置檔案my.ini
server-id=1
log-bin=mysql-bin.log
server-id=2
#啟用從庫日誌,這樣可以進行鏈式複製
log-slave-updates
#從庫是否只讀,0表示可讀寫,1表示只讀
read-only=1
#只複製某個表
replicate-do-table=tablename
#只複製某些表(可用匹配符)
replicate-wild-do-table=tablename%
#只複製某個庫
replicate-do-db=dbname
#只複製某些庫
replicte-wild-do-db=dbname%
#不復制某個表
replicate-ignore-table=tablename
#不復制某些表
replicate-wild-ignore-table=tablename%
#不復制某個庫
replicate-ignore-db=dbname
#複製完的sql語句是否立即從中繼日誌中清除,1表示立即清除
relay-log-purge=1
#從伺服器主機,用於show slave hosts生成從庫清單
report-host=hostname
master:
mysql> grant replication slave on *.* to 'rep'@'%' identified by 'rep';
Query OK, 0 rows affected (0.00 sec)
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000015 | 433 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.01 sec)
salve:
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.1.201',
-> MASTER_USER='rep',
-> MASTER_PASSWORD='rep',
-> MASTER_LOG_FILE='mysql-bin.000015',
-> MASTER_LOG_POS=433;
Query OK, 0 rows affected (0.07 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.201
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000015
Read_Master_Log_Pos: 615
Relay_Log_File: node2-relay-bin.000002
Relay_Log_Pos: 433
Relay_Master_Log_File: mysql-bin.000015
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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: 615
Relay_Log_Space: 588
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:
1 row in set (0.00 sec)
master:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
slave:
mysql> show processlist;
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+
| 1 | root | localhost | test | Query | 0 | NULL | show processlist |
| 2 | system user | | NULL | Connect | 647 | Waiting for master to send event | NULL |
| 3 | system user | | NULL | Connect | 240 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+
3 rows in set (0.00 sec)
master:
mysql> show processlist;
+----+------+-------------+------+-------------+------+----------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-------------+------+-------------+------+----------------------------------------------------------------+------------------+
| 1 | rep | node2:56986 | NULL | Binlog Dump | 1837 | Has sent all binlog to slave; waiting for binlog to be updated | NULL |
| 2 | root | localhost | test | Query | 0 | NULL | show processlist |
+----+------+-------------+------+-------------+------+----------------------------------------------------------------+------------------+
2 rows in set (0.02 sec)
在從庫的資料目錄下,有幾個和複製相關的檔案需要說明一下:
*-reloay-bin.* 從主庫同步過來的Bin log檔案,也叫中繼日誌
master.info 主庫帳號資訊和同步資訊,這裡記錄了複製使用者名稱和密碼,需要保護好許可權。
relay-log.info 跟蹤執行同步過來的Bin log的執行情況
參考 http://www.ningoo.net/html/2007/mysql_replication_configuration.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/758322/viewspace-680438/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- The slave I/O thread stops because master and slave have equal MySQL server UUIDthreadASTMySqlServerUI
- Mysql 5.6 Master和Slave 主備切換MySqlAST
- Mysqldump實現mysql的master-slave主從複製MySqlAST
- mysql slave 跟進 master 的關鍵狀態指標MySqlAST指標
- Mysql Master-slave複製簡單配置記錄MySqlAST
- MySQL報錯Slave: received end packet from server, apparent master shutdownMySqlServerAPPAST
- Setup MariaDB Master/Slave Replication for Docker MariaDBASTDocker
- Innobackupex實現mysql線上搭建master-slave主從複製MySqlAST
- 故障案例:主從同步報錯Fatal error: The slave I/O thread stops because master and slave have equal MySQL server主從同步ErrorthreadASTMySqlServer
- 分散式資料中的坑(一)Master-Slave架構分散式AST架構
- 資料庫讀寫分離Master-Slave資料庫AST
- CentOS中MySQL5.6 資料庫主從(Master/Slave)同步安裝與配置詳解CentOSMySql資料庫AST
- 使用etcd選舉sdk實踐master/slave故障轉移AST
- 實屬無奈!Redis 作者被迫修改 master-slave 架構的描述RedisAST架構
- 基於Kubernetes構建企業Jenkins master/slave CI/CD平臺JenkinsAST
- MySQL複製跳過錯誤--slave_skip_errors、sql_slave_skip_counter、slave_exec_modeMySqlError
- MySQ 資料庫主從同步安裝與配置詳解(Master/Slave)資料庫主從同步AST
- 手把手教你寫一個自己的 master-slave 架構的 TCP 伺服器AST架構TCP伺服器
- MYSQL Slave開機啟動指令碼MySql指令碼
- MySQL中slave監控的延遲情況分析MySql
- jenkins slave節點上的job構建記錄 都只會在master伺服器JenkinsAST伺服器
- MySQL5.7 Master-Master主主搭建for Centos7MySqlASTCentOS
- Redis for linux原始碼&叢集(cluster)&主從(master-slave)&哨兵(sentinel)安裝配置RedisLinux原始碼AST
- [MySQL進階之路][No.0002] SHOW SLAVE STATUSMySql
- MySQL複製命令slave被REPLICA命令取代MySql
- 1.MongoDB 2.7主從複製(master –> slave)環境基於時間點的恢復MongoDBAST
- mysql MASTER_POS_WAIT函式MySqlASTAI函式
- 從Mysql slave system lock延遲說開去MySql
- MySQL:關於Wating for Slave workers to free pending events等待MySql
- 故障分析 | MySQL : slave_compressed_protocol 導致 crashMySqlProtocol
- MySQL:show slave status 關鍵值和MGRrelay log的清理策略MySql
- Mysql 建立心跳錶來監控Replication的Slave是否延遲MySql
- MySQL主從複製中的“show slave status”詳細含義MySql
- zabbix應用-監控mysql slave 主從狀態MySql
- MySQL:slave_skip_errors引數對MGR可用性的影響MySqlError
- MySQL 關於slave端Retrieved_Gtid_Set的讀取改進初探MySql
- 【MySQL】六、常見slave 延遲原因以及解決方法MySql
- MySQL主從複製配置引數 -- logs-slave-updatesMySql
- mysql之 誤用SECONDS_BEHIND_MASTER衡量MYSQL主備的延遲時間MySqlAST