MySQL同步就是怎么簡單,鄙視那些自私自利的人, 本人的筆記: http://note.youdao.com/share/?id=d70f203ee0407a475fcfa47b62b51500nbsp;技術是需要共享的麻煩朋友幫收藏頂一頂。 ###################################################### MySQL server-id=
MySQL同步就是怎么簡單,鄙視那些自私自利的人,server-id = 1 log-bin=mysql-bin log-slave-updates #slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=1 replicate_wild_ignore_table=mysql.% replicate_wild_ignore_table=test.% innodb_file_per_table=1 binlog_format =mixed
server-id = 2 log-bin=mysql-bin log-slave-updates #slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=2 replicate_wild_ignore_table=mysql.% replicate_wild_ignore_table=test.% innodb_file_per_table=1 binlog_format =mixed
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.46 Ahost
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.47 Bhost
###################################### # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT -A INPUT -j REJECT –reject-with icmp-host-prohibited -A FORWARD -j REJECT –reject-with icmp-host-prohibited COMMIT ##################################### 防火墻 1) 重啟后生效 開啟: chkconfig iptables on 關閉: chkconfig iptables off 防火墻 2) 即時生效,重啟后失效 開啟: service iptables start 關閉: service iptables stop ##################################### 一般是事務回滾造成的: 解決辦法: mysql> slave stop; mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; mysql> slave start; ######################################
解決辦法一、 Slave_SQL_Running: No 1.程序可能在slave上進行了寫操作 2.也可能是slave機器重起后,事務回滾造成的. Last_SQL_Errno: 1677 Last_SQL_Error: Column 1 of table 'test.t' cannot be converted from type 'int' to type 'bigint(20)' 解決方法:這個案例是從網上找到的,自己動手實驗了一把。從錯誤信息來看表面上是由于在slave上無法執行一條轉換字段類型的SQL語句。實際上并不是有這種語句直接引起的,而是間接引起的(之前某些操作導致主從表字段類型不一致,接下來對這個表進行DML時就會報錯)。它的意思是在對這個表t進行DML操作時,發現主從上表結果不一致,比如這里是說在主上t的字段1是int類型,但是從上t的字段1是bigint類型,所以報錯。那么為什么要報錯呢?這是從安全角度考慮,因為如果字段類型不一致可能會導致數據截斷之類的問題。那么解決方法呢?通過參數slave_type_conversions進行控制,它有三種取值: ALL_LOSSY:僅支持有損轉換,什么叫有損?比如一個值本來是bigint存儲為9999999999999,現在轉換為int類型勢必會要截斷從而導致數據不一致。 ALL_NON_LOSSY:僅支持無損轉換,只能在無損的情況下才能進行轉換 ALL_LOSSY,ALL_NON_LOSSY:有損/無算轉換都支持 空,即不設置這個參數:必須主從的字段類型一模一樣。 注意: 前面說的這幾中情況都只在binlog_format=ROW的情況下才有效。 Last_SQL_Errno: 1194 Last_SQL_Error: Error 'Table 'traincenter' is marked as crashed and should be repaired' on query. Default database: 'basketballman'. Query: 'update traincenter set points='4',pointstime='1361912066' where uid = '1847482697' limit 1' 解決方法:myisam表traincenter損壞,直接repair table即可。至于為什么myisam類型表比innodb更容易損壞,我覺得有兩個原因:1,innodb有double write機制,損壞或者half write的頁可以用它恢復,第二innodb是事務引擎,都有操作都是事務的,而myisam是非事務的,存在寫一半但是操作終止情況。 Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' 解決方法:主庫上的binlog文件已經不存在但是在index file中確有相應記錄存在。我這里發生這個錯誤的原因在于由于復制中斷時間很長,報警出來一直沒人處理,這個中斷時間超過master上binlog超期時間,等恢復復制時需要的binlog已經由于其超期而被刪掉,沒辦法只好重建這個實例了。以大家都要引以為戒 stop slave; reset slave; slave start; Last_IO_Errno: 1593 Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it). 解決方法:主從配置的server-id一樣,而在主從復制環境中server-id一樣的binlog events都會被過濾掉。具體server-id的含義可以了解一下復制原理。這個一般是因為拷貝配置文件時忘記修改server-id導致,遇到這類問題也比較容易,平時操作謹慎一點即可。 Last_Errno: 1053 Last_Error: Query partially completed on the master (error on master: 1053) and was aborted. There is a chance that your master is inconsistent at this point. If you are sure that your master is ok, run this query manually on the slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE; . Query: 'insert into ... 解決方法:查詢在master上部分完成,然后終止了。這馬上又能想到是myisam表,結果也正是這樣。由于myisam不支持事務所以可能存在一個查詢完成一部分然后失敗的情況。解決方法一般也就是提示信息給出的跳過一個binlog event。不過確認跳過之前最好還是查詢一下master上是否真的存在相應的記錄,因為錯誤信息同時還會給出它認為在master上執行一部分然后終止的查詢語句。 Last_SQL_Errno: 1666 Last_SQL_Error: Error executing row event: 'Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.' 解決方法:這個案例的背景是做一個ABC結構的復制,B、C中設定的binlog_format=statement,A中的是MIXED,所以當B嘗試重做A過來的relay log,然后記錄binlog(傳給C)時發現relay log的binlog_format與自己設定的binlog_format不一致。我當時就是直接先更改BC的binlog_format=MIXED解決。 Last_Errno: 1032 Last_Error: Could not execute Update_rows event on table db.table; Can't find record in 'table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000064, end_log_pos 158847 解決方法:這個是在binlog_format=row復制下發生的。原因是因為row格式復制是最嚴格的,所以在mysql看來如果在從庫上找不到要更新的這條記錄,那么就代表主從數據不一致,因此報錯。另外順便說一句,對于row格式binlog,如果某個更新操作實際上并沒有更新行,這個操作是不會記binlog的,因為row格式的binlog宗旨就是只記錄發生了改變的行。所以這個解決辦法根據你自己實際應用來定,最好的方法還是重做slave吧,這樣更放心。 Last_Errno: 28 Last_Error: Error in Append_block event: write to '/tmp/SQL_LOAD-32343798-72213798-1.data' failed 解決方法: 首先說錯誤原因:主庫執行load data infile,同步到從庫后load data infile存放的文件默認是放在/tmp(由參數slave_load_tmpdir控制),而/tmp空間不夠因此報錯。因此只要將從庫上slave_load_tmpdir設置到一個磁盤空間足夠大的分區就行。
①########################## show variables like 'server_id'; ②########################## server-id = 1 log-bin=mysql-bin log-slave-updates #slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=1 innodb_file_per_table=1 binlog_format =mixed ③########################## GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO'repl'@'%' IDENTIFIED BY '123456'; ④########################## SHOW GRANTS FOR repl@'%'; ⑤########################## FLUSH PRIVILEGES; ⑥########################## show master status\G *************** 1. row ************** File: mysql-bin.000005 Position: 37312 Binlog_Do_DB: Binlog_Ignore_DB: ⑦########################## change master to master_host='192.168.1.47', master_user='repl', master_password='123456', master_log_file='mysql-bin.000006', master_log_pos=11792, master_port=3306; ⑧########################## show slave status\G ⑨########################## start slave; ############################ 如果起不來就reset slave ############################
①########################## show variables like 'server_id'; ②########################## server-id = 9 log-bin=mysql-bin log-slave-updates #slave-skip-errors=all sync_binlog=1 auto_increment_increment=2 auto_increment_offset=2 innodb_file_per_table=1 binlog_format =mixed ③########################## GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO'repl'@'%' IDENTIFIED BY '123456'; ④########################## SHOW GRANTS FOR repl@'%'; ⑤########################## FLUSH PRIVILEGES; ⑥########################## show master status\G ************* 1. row **************** File: mysql-bin.000006 Position: 11792 Binlog_Do_DB: Binlog_Ignore_DB: ⑦########################## change master to master_host='192.168.1.46', master_user='repl', master_password='123456', master_log_file='mysql-bin.000005', master_log_pos=37312, master_port=3306; ⑧########################## show slave status\G ⑨########################## start slave; ############################ 如果起不來就reset slave ############################
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com