长话短说,我发现的expire_log_days = 3
有点太晚了。我的 /var/log 目录完全充满了旧的 mysql-bin 文件,根据 google/SE 搜索,强烈建议不要手动删除它们。
问题是,我无法进入 MySQL shell 来清除它们,也无法使用新的配置设置启动服务expire_log_days
。
我删除了一些较旧的非 MySQL 日志(约 500mb),但仍然无法启动 mysql。
有没有不那么痛苦的解决方法?
[root@box mariadb]# systemctl restart mariadb.service
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
[root@box mariadb]# journalctl -xe
-- Subject: Unit session-203.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-203.scope has begun starting up.
Dec 07 14:01:35 my.sql.box systemd[1]: Starting MariaDB database server...
-- Subject: Unit mariadb.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mariadb.service has begun starting up.
Dec 07 14:01:36 my.sql.box mysqld_safe[23884]: 161207 14:01:36 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Dec 07 14:01:36 my.sql.box mysqld_safe[23884]: 161207 14:01:36 mysqld_safe Starting mysqld daemon with databases from /data/db/mysql
Dec 07 14:01:36 my.sql.box mysqld_safe[23884]: 161207 14:01:36 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
Dec 07 14:01:37 my.sql.box systemd[1]: mariadb.service: control process exited, code=exited status=1
Dec 07 14:01:37 my.sql.box systemd[1]: Failed to start MariaDB database server.
-- Subject: Unit mariadb.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mariadb.service has failed.
--
-- The result is failed.
Dec 07 14:01:37 my.sql.box systemd[1]: Unit mariadb.service entered failed state.
Dec 07 14:01:37 my.sql.box systemd[1]: mariadb.service failed.
Dec 07 14:01:37 my.sql.box audispd[4973]: node=my.sql.box type=SERVICE_START msg=audit(1481137297.301:1657): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=
Dec 07 14:01:37 my.sql.box polkitd[4981]: Unregistered Authentication Agent for unix-process:23850:300226 (system bus name :1.460, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_U
[root@box log]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-12-07 14:09:17 EST; 7s ago
Process: 24840 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
Process: 24838 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 24810 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 24838 (code=exited, status=0/SUCCESS)
Dec 07 14:09:12 my.sql.box systemd[1]: Starting MariaDB database server...
Dec 07 14:09:13 my.sql.box mysqld_safe[24838]: 161207 14:09:13 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Dec 07 14:09:13 my.sql.box mysqld_safe[24838]: 161207 14:09:13 mysqld_safe Starting mysqld daemon with databases from /data/db/mysql
Dec 07 14:09:16 my.sql.box mysqld_safe[24838]: 161207 14:09:16 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
Dec 07 14:09:17 my.sql.box systemd[1]: mariadb.service: control process exited, code=exited status=1
Dec 07 14:09:17 my.sql.box systemd[1]: Failed to start MariaDB database server.
Dec 07 14:09:17 my.sql.box systemd[1]: Unit mariadb.service entered failed state.
Dec 07 14:09:17 my.sql.box systemd[1]: mariadb.service failed.
[root@box log]#
答案1
假设你的二进制日志占用了大部分磁盘空间。你需要做的就是移动至少一个二进制日志存放到具有额外磁盘空间的单独分区。只移动不删除。然后在 mysql 控制台中执行PURGE BINARY LOGS TO 'binlog.file';
并选择比您在上一步中移动的日志文件更旧的二进制日志。这应该会释放更多磁盘空间。然后将二进制日志文件移回其正确位置,如果需要,清除更多二进制日志。
答案2
您应该通过注释 my.cnf 文件中的所有expire_log_days
或来暂时禁用这些日志log_bin
,以关闭服务器日志记录,然后手动移动/删除 /var/log 二进制文件。
然后启动服务器,再次启用注释的标志并重新启动 MariaDB。