MySQL日志旋转错误

Ada*_*m D 6 mysql cron logrotate 16.04

我是 Linux 新手,已经设置了一个运行 Ubuntu 16.04 的 VPS,带有 postfix、dovecot 和 rouncube,使用 mariadb 作为数据库。一切似乎都正常,但我经常收到以下电子邮件:

/etc/cron.daily/logrotate:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
error: error running shared postrotate script for '/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/mariadb-slow.log /var/log/mysql/error.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1
Run Code Online (Sandbox Code Playgroud)

我已经做了一些搜索,发现一个帖子建议我需要创建一个 /root/.my.cnf 文件,我已经完成并重新启动了服务器等,但我仍然收到错误。我的/root/.my.cnf的内容如下:

[mysqladmin]
password = *mypassword*
user = root

[mysql]
password = *mypassword*
Run Code Online (Sandbox Code Playgroud)

有谁知道我是否遗漏了什么或者我需要配置什么才能让它使用mysql密码?

谢谢

Ava*_*ava 6

这可能是使用 mariadb 时“库存”配置中的一个错误,而不是尚未淘汰的 mysql,因为我依稀记得当我从 mysql 转移到 mariadb 时遇到了类似的事情。

您将需要查看/etc/logrotate.d/mysql-server在 postrotate 中运行的内容。你可能会有这样的事情:

test -x /usr/bin/mysqladmin || exit 0
if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then
    # If this fails, check debian.conf!
    mysqladmin --defaults-file=/etc/mysql/debian.cnf flush-logs
fi
Run Code Online (Sandbox Code Playgroud)

Ubuntu 可能正在寻找那里,因此请尝试查看/etc/mysql/debian.cnf并查看设置的内容。