標籤:主從複製 har htm 需要 同步資料 uda 語句 size lock
Mysql主從複製也叫作Replication
1 他的原理
http://www.cnblogs.com/crazylqy/p/4065374.html
2 他的實現
這裡有一個專題專門對mysql從曆史到發展到架構,到mysql叢集都有比較詳細的介紹:http://www.cnblogs.com/crazylqy/category/625963.html
3 具體實現步驟
http://www.cnblogs.com/alvin_xp/p/4162249.html
4 遇到的問題
1)MySQL error code 1872 (ER_SLAVE_RLI_INIT_REPOSITORY): Slave failed to initialize relay log info structure from the repository
解決辦法:重設從資料庫連接,http://www.cnblogs.com/Bccd/p/5856716.html
5 詳細的主要資料庫配置參考
[client]
port=5869
[mysql]
default-character-set=utf8
[mysqld]
port=5869
#basedir=D:/mysql-5.6.21-winx64
#datadir=D:/mysql-5.6.21-winx64/data
character-set-server=utf8
default-storage-engine = MYISAM
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-bin=mysql-bin #slave會基於此log-bin來做replication
log-bin-index=mysql-bin.index
server-id=11 #master的標示
read-only=0
binlog-do-db=xsmart_mssp_basedatacenter #同步資料庫,可以複製寫多個
binlog-ignore-db=mysql #忽略需要同步的資料庫,可以複製寫多個
log-slave-updates=1 #這個參數一定要加上,否則不會給更新的記錄寫入到二進位檔案中
innodb_flush_log_at_trx_commit=1
sync_binlog=1
skip-external-locking #加上可以避免因資源鎖引起MySQL服務停止
skip-name-resolve #加上可以避免因資源鎖引起MySQL服務停止
max_connections=300
query_cache_size=186M
table_open_cache=1520
tmp_table_size=67M
thread_cache_size=38
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=67M
key_buffer_size=290M
read_buffer_size = 1M
read_rnd_buffer_size = 8M
sort_buffer_size = 1M
#innodb_additional_mem_pool_size=80M
#innodb_flush_log_at_trx_commit=0
#innodb_log_buffer_size=8M
#innodb_buffer_pool_size=2G
#innodb_log_file_size=1024M
#innodb_thread_concurrency=18
#innodb_support_xa = 1
#innodb_file_per_table = 1
#innodb_file_format = Barracuda
#interactive_timeout = 2147482
#wait_timeout = 2147482
interactive_timeout = 86400
wait_timeout = 86400
max_allowed_packet = 1G
# binlog
#log_bin = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.log
#log_bin_index = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.index
#log_error = D:/mysql-5.6.21-winx64/log/mysql-error.log
sync_binlog = 1
expire_logs_days = 7
binlog_format = MIXED
[mysqldump]
max_allowed_packet = 1G
6 主要資料庫執行的語句參考
CREATE USER repl; `建立一個主從複製的資料庫使用者,rel
GRANT REPLICATION SLAVE ON *.* TO ‘repl‘@‘192.168.50.%‘ IDENTIFIED BY ‘mysql‘;‘為這個使用者賦許可權,且他的密碼為mysql
SHOW MASTER STATUS;‘顯示主要資料庫主從複製運行狀態
7 從資料庫執行語句參考
STOP SLAVE;‘停止與主要資料庫串連
RESET SLAVE ALL;‘重設與主要資料庫串連
CHANGE MASTER TO MASTER_HOST=‘192.168.50.192‘,
MASTER_PORT=5869,
MASTER_USER=‘repl‘,
MASTER_PASSWORD=‘mysql‘,
MASTER_LOG_FILE=‘mysql-bin.000006‘,
MASTER_LOG_POS=5750;
START SLAVE;‘啟動與主要資料庫串連並開始主從複製
SHOW SLAVE STATUS;’查看主從複製運行狀態,當看到Slave_IO_Running和Slave_SQL_Running都為Yes的時候,證明同步成功,否則就看sql執行錯誤記錄檔
Mysql主從複製