1:當經過 TCP/IP 鏈接 MySQL 遠程主機時,出現 ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104 。若是是
在linux shell命令行中直接打 mysql 命令,可以順利連上 MySQL,執行查詢語句也比較正常,但若是執行 STOP SLAVE; 命令時就隨機出現
ERROR 2013 (HY000): Lost connection to MySQL server during query 問題。而若是把操做命令寫到腳本文件再去執行該腳本文件的話,
則必然出現 Lost connection to MySQL server at 'reading initial communication packet', system error: 111
要是不管經過什麼途徑遠程訪問都出現錯誤能夠認爲是系統有防火牆之類的限制,但如今這種奇怪的抽筋現象讓人百思不得其解。
最後找到的解決方法是在 my.cnf 裏面的 [mysqld] 段增長一個啓動參數:mysql
skip-name-resolvelinux
###mysql主從,經過status 查看
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
若是不所有是yes的話就說明主從有問題,就得去從庫分析錯誤日誌了
###根據錯誤日誌查看對應問題
stop SLAVE ;
reset slave
CHANGE MASTER TO MASTER_LOG_FILE='mysqlcncnmaster.000080', MASTER_LOG_POS=0;
start SLAVE ; sql
不行的話看下是否是mysql資源被其餘進程佔用
重啓mysql服務
經過mysqlbinlog轉換最新的binlog日誌文件,看下是否是在同步以前的事件
mysqlbinlog /var/log/mysql/mysql-bin.002743 > test.txtshell
result = commands.getoutput('mysql -uroot -p1qaz#EDC -e "show slave status\G" |egrep -w "Slave_IO_Running|Slave_SQL_Running" |awk "{print $2}"|wc -l')vim
###slave狀態不對
Slave_IO_Running: Yes
Slave_SQL_Running: No緩存
報錯:Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are:
the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log),
the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code.
If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.服務器
###找到出錯前讀取到的最新位置,從新設置從主的同步日誌和位置
Relay_Master_Log_File: mysql-bin.002757
Read_Master_Log_Pos: 84194890ui
###修復
stop slave;
change master to master_log_file='mysql-bin.002757',master_log_pos=84194890;
start slave;this
並無解決
show slave status\G
Slave_IO_Running: No
Slave_SQL_Running: Yesspa
報錯:Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
查看從庫錯誤日誌
vim /var/log/mysql/error.log
2017-08-08 09:13:43 29950 [Note] Slave I/O thread killed while reading event
2017-08-08 09:13:43 29950 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.003003', position 90529022
顯示退出的時候讀取到這個文件的這個點
再次中止從庫,修改與主的同步位置後恢復
Seconds_Behind_Master: 395 ###與主相差的同步時間點也OK
######刪除數據表,從新建立時報錯
Tablespace for table '`zabbix`.`history_uint`' exists. Please DISCARD the tablespace before IMPORT
#####解決方法
一、刪除這個表所在數據目錄關於這個表的全部文件
二、命令行進入數據清除緩存,如若不清楚依然會報此錯
use zabbix
flush privileges
三、校驗,查看是否有新數據產生
mysql雙主主鍵衝突
建議相似雙主這種狀況:
事先設置好offset和increment的值,即:實現設置好自增字段的初始值和步長。主庫A爲奇數起步,主庫B爲偶數起步。二者都採用相同的步長。
1)、設置主主服務器的自增加偏移位置不一樣:
A :auto_increment_offset=3
B :auto_increment_offset=4
2)、設置主主服務器步長相同:
auto_increment_increment=2