mysql更新日志问题

时间:2021-12-13 19:48:37
[root@localhost ~]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]

故障:今天在维护以前数据库日志的时候,把目录下所有的日志都压缩拷贝到本地了以防以后查询使用,压缩之后清理了日志目录下/var/log/mysqllog所有的日志,然后重启服务

/etc/init.d/mysqld restart

[root@localhost ~]# /etc/init.d/mysqld start
MySQL Daemon failed to start.
正在启动 mysqld: [失败]

查看日志,

[root@localhost ~]# tailf /var/log/mysqld.log
:: [ERROR] Failed to open log (file '/var/log/mysqllog/myupdate.000050', errno )
:: [ERROR] Could not open log file
:: [ERROR] Can't init tc log
:: [ERROR] Aborting :: InnoDB: Starting shutdown...
:: InnoDB: Shutdown completed; log sequence number
:: [Note] /usr/libexec/mysqld: Shutdown complete :: mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

这个文件已经被我删除/var/log/mysqllog/myupdate.000050,是更新日志最后一个文件,所以mysql找不到这个文件,应该是还准备往这个文件里面写日志,所以我想是不是有什么命令应该可以让mysql更新日志重新滚动呢,在网上找了好久没找到,最后看见了在目录下面myupdate.index 这个文件。

[root@localhost mysqllog]# ls
log.sh mycommon-.log mycommon-.log mycommon-.log mycommon-.log mycommon-.log mycommon.log myupdate.index
[root@localhost mysqllog]# more myupdate.index
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.
/var/log/mysqllog/myupdate.

原来这是记录了所有文件的索引信息,是不是清空了就会重新创建000001文件呢,试了一下。

[root@localhost mysqllog]# >myupdate.index 
[root@localhost ~]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]

果然可以正常启动了,再看目录下面也确实创建了000001,不知道有没有像我一样遇到这样问题的朋友,我觉得应该会有什么命令可以重载myupdate.index文件,本人数据库新手,虽然这个故障可能对于别人比较简单,记录下来供刚入门的朋友参考。