mysql 5.7.17 开启二进制日志后启动失败

问题描述:

系统版本:Ubuntu 16.04
MySQL版本:5.7.17

安装方式,通过 MySQL APT 源安装。(MySQL官网下载)
只要开启二进制日志 log-bin 选项,就启动失败,而且在 mysql 自己的错误日志里面没有日志信息。

问题复现:

安装好 MySQL 后,以默认配置可以正常启动 mysql.

尝试开启二进制日志:log-bin=mysql-bin

启动失败!

/etc/mysql/mysql.conf.d# /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!

经历几小时查找原因,找到解决办法,添加如下选项
server-id=1

试了下确实可以了。

然后回来看官方文档是否又说明,真的有!

In MySQL 5.7.2 and earlier, if you start a master server without using --server-id to set its ID, the default ID is 0. In this case, the master refuses connections from all slaves, slaves refuse to connect to the master, and the server sets the server_id system variable to 1. In MySQL 5.7.3 and later, the --server-id must be used if binary logging is enabled, and a value of 0 is not changed by the server. If you specify --server-id without an argument, the effect is the same as using 0. In either case, if the server_id is 0, binary logging takes place, but slaves cannot connect to the master, nor can any other servers connect to it as slaves. (Bug #11763963, Bug #56718)

MySQL 5.7.3 版本后,如果要开启二进制日志,必须同时开启 --server-id 选项。
server-id 不要设置为0(不支持主从复制),应该设置为 1 或者其他值。

补充

之前奇怪为什么 mysql.err 里面没有记录错误日志。
今天看到这篇文章:AppArmor and MySQL
https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

才明白或许应该去 /var/log/syslog 查看日志。然后尝试重现昨天的错误,也就是开启 log-bin 选项,但是没有开启 server-id 选项,然后 tail -f 观察 syslog 的日志输出:

Mar 17 09:57:58 guli-Ubuntu1 mysqld[2825]: 2017-03-17T01:57:58.021561Z 0 [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id. Please refer to the proper server start-up parameters documentation
Mar 17 09:57:58 guli-Ubuntu1 mysqld[2825]: 2017-03-17T01:57:58.022512Z 0 [ERROR] Aborting
Mar 17 09:57:58 guli-Ubuntu1 mysqld[2825]: Initialization of mysqld failed: 0
Mar 17 09:57:58 guli-Ubuntu1 mysqld[2825]: 2017-03-17T01:57:58.029601Z 0 [Note] Binlog end
Mar 17 09:57:58 guli-Ubuntu1 mysqld[2825]: 2017-03-17T01:57:58.043989Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

果然是在这里输出错误日志。而且说得很明白 you haven't provided the mandatory server-id。

.. 昨天花了那么多时间在网上找原因..真是一个教训,以后遇到启动时出问题,一定要看看 syslog 的记录。

还没完。

这个坑可以绕过去了。但要在 Ubuntu 下定制自己的数据目录,还有一个坑,这个坑跟 apparmor 有关系。

mysql 和 apparmor 就再另开一篇博文来讲了。

你可能感兴趣的:(mysql 5.7.17 开启二进制日志后启动失败)