# MySQL问题小记:ERROR: Got error reading packet from server: Could not open log file

MySQL问题小记:ERROR: Got error reading packet from server: Could not open log file

实验环境

操作系统:CentOS release 6.8 (Final)

数据库:MySQL 5.7.19

错误还原

我在尝试执行mysql binlog备份是出现错误,脚本如下:

获取当前binlog名:

[[email protected]] /home/mysql/bin # MYSQL_BIN=`mysql -uroot -h concar-mysql01 -P3306  -pxxx -e"SHOW BINARY LOGS;"|sed 1d|awk '{print $1}'|xargs`
mysql: [Warning] Using a password on the command line interface can be insecure.

备份所有被找到的binlog:

[[email protected]] /home/mysql/bin # mysqlbinlog --read-from-remote-server --host=concar-mysql01 --port=3306 --user=root --password=xxx --result-file=/opt/mysql/bak/concar-mysql01.binlogbak $MYSQL_BIN
mysqlbinlog: [Warning] Using a password on the command line interface can be insecure.
ERROR: Got error reading packet from server: Could not open log file

出现错误,备份也失败了:

ERROR: Got error reading packet from server: Could not open log file

问题分析

根据错误判断是找不到指定的log文件,手动查看binlog路径下的文件:

[[email protected]] /opt/mysql/data # ll /opt/mysql/data/binlog/
total 835656
-rw-r-----. 1 mysql mysql 104857726 Apr 24 04:48 binlog.006870
-rw-r-----. 1 mysql mysql 104857719 Apr 24 05:37 binlog.006871
-rw-r-----. 1 mysql mysql 104858168 Apr 24 06:16 binlog.006872
-rw-r-----. 1 mysql mysql 104857740 Apr 24 07:03 binlog.006873
-rw-r-----. 1 mysql mysql 104858133 Apr 24 07:43 binlog.006874
-rw-r-----. 1 mysql mysql 104858002 Apr 24 08:23 binlog.006875
-rw-r-----. 1 mysql mysql 104857855 Apr 24 09:12 binlog.006876
-rw-r-----. 1 mysql mysql 104859650 Apr 24 11:16 binlog.006877
-rw-r-----. 1 mysql mysql   3095527 Apr 24 11:54 binlog.006878
-rw-r-----. 1 mysql mysql   9238560 Apr 24 14:06 binlog.006879
-rw-r-----. 1 mysql mysql    258284 Apr 24 14:10 binlog.006880
-rw-r-----. 1 mysql mysql   3768795 Apr 24 15:05 binlog.006881
-rw-r-----. 1 mysql mysql     23800 Apr 24 15:06 binlog.006882
-rw-r-----. 1 mysql mysql    360970 Apr 24 15:09 binlog.006883
-rw-r-----. 1 mysql mysql      2368 Apr 24 15:06 binlog.index

再查看脚本运行结果:

[[email protected]] /opt/mysql/data # mysql -uroot -h concar-mysql01 -P3306  -pxxx -e"SHOW BINARY LOGS;"|sed 1d|awk '{print $1}'|xargs
mysql: [Warning] Using a password on the command line interface can be insecure.
binlog.006820 binlog.006821 binlog.006822 binlog.006823 binlog.006824 binlog.006825 binlog.006826 binlog.006827 binlog.006828 binlog.006829 binlog.006830 binlog.006831 binlog.006832 binlog.006833 binlog.006834 binlog.006835 binlog.006836 binlog.006837 binlog.006838 binlog.006839 binlog.006840 binlog.006841 binlog.006842 binlog.006843 binlog.006844 binlog.006845 binlog.006846 binlog.006847 binlog.006848 binlog.006849 binlog.006850 binlog.006851 binlog.006852 binlog.006853 binlog.006854 binlog.006855 binlog.006856 binlog.006857 binlog.006858 binlog.006859 binlog.006860 binlog.006861 binlog.006862 binlog.006863 binlog.006864 binlog.006865 binlog.006866 binlog.006867 binlog.006868 binlog.006869 binlog.006870 binlog.006871 binlog.006872 binlog.006873 binlog.006874 binlog.006875 binlog.006876 binlog.006877 binlog.006878 binlog.006879 binlog.006880 binlog.006881 binlog.006882 binlog.006883

脚本查出来很多已删除的binlog,带入到备份语句中去,难怪会报找不到文件

问题解决

进入mysql手动清理binlog:

[[email protected]] /opt/mysql/data # mysql -uroot -h concar-mysql01 -P3306  -pxxx

mysql> PURGE MASTER LOGS BEFORE '2019-04-24 15:00:01';
Query OK, 0 rows affected, 50 warnings (0.10 sec)

再次使用脚本查看binlog:

[[email protected]] /opt/mysql/data # mysql -uroot -h concar-mysql01 -P3306  -pxxx -e"SHOW BINARY LOGS;"|sed 1d|awk '{print $1}'|xargs
mysql: [Warning] Using a password on the command line interface can be insecure.
binlog.006881 binlog.006882 binlog.006883 binlog.006884

返回结果已正常

总结

删除binlog时,最好能进入mysql使用purge命令删除。如果单纯使用rm命令删除binlog,不会清理binlog.index里面的记录,这将导致数据库在show binary logs时依然显示已删除的binlog。

发布了136 篇原创文章 · 获赞 58 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/sunbocong/article/details/89496996
今日推荐