標籤:ica 語句 password hang status ssl server date backup
瞭解MySQL主從複製:
MySQL的複製功能是構建大型,高效能應用程式的基礎。主從複製是指一台伺服器充當主要資料庫伺服器(master),另一台或多台伺服器充當從資料庫伺服器(slave),主伺服器中的資料自動複製到從伺服器之中。MySQL主從複製的基礎是主伺服器對資料庫修改並記錄二進位日誌,從伺服器通過主伺服器的二進位日誌自動執行更新。
複製解決的問題:
- 資料分布 (Data distribution)
- 負載平衡 (Load balancing)
- 高可用及容錯 (High availability and failover)
- 備份(Backups)
MySQL複製的類型:
- SBR(statement based replicate):基於語句的複製,在主伺服器上執行的SQL語句,在從伺服器上執行同樣的語句。
- RBR(row based replicate):基於行的複製,將主伺服器上改變的內容複寫過去。
- MIX(mixed):預設採用基於語句的複製,一旦發現基於語句的無法精確的複製時,就會採用基於行的複製。
MySQL主從複製原理:
- master將改變的內容記錄到二進位日誌中(binary log),這些記錄叫做二進位日誌事件(binary log events);
- slave通過 IO thread 接收master的binary log,並寫入到slave的 realay log(中繼日誌)中,SQL thread 從realay log 讀取事件,並更新slave資料。
MySQL主從配置:
master配置:
禁用GTID:gtid_mode=OFF
server_id:103306 (建議IP後兩位加資料庫連接埠號碼)
log_bin:log_bin=ON
binlog_format:binlog_format=ROW (可選:mixed|statement )
建立複製帳號:
grant replication slave on *.* to ‘repl‘@‘%‘ identified by ‘password‘;
查看master狀態:
show master status\G;
查看Binlog Dump:
show processlist\G;
Command: Binlog Dump
State: Master has sent all binlog to slave; waiting for more updates
slave配置:
禁用GTID:gtid_mode=OFF
server_id:113306 (建議IP後兩位加資料庫連接埠號碼)
log_bin:log_bin=ON
log_slave_updates:log_slave_updates=ON
串連主庫:
CHANGE MASTER TO MASTER_HOST=‘192.168.100.10‘, MASTER_USER=‘repl‘, MASTER_PASSWORD=‘password‘, MASTER_PORT=3306, MASTER_LOG_FILE=‘mysql-bin.000002‘, MASTER_LOG_POS=3141;
開啟同步:
start slave;
其他命令:
stop slave:關閉同步start slave io_thread:開啟IO線程,stop 關閉start slave sql_thread:開始SQL線程,stop 關閉
查看slave狀態:
show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
IO thead 和 SQL thead線程:
show processlist\G;
Command: Connect
State: Waiting for master to send event
Command: Connect
State: Slave has read all relay log; waiting for more updates
MySQL 主從複製