mysql 5.7.17 開(kāi)啟二進(jìn)制日志后啟動(dòng)失敗

問(wèn)題描述:

系統(tǒng)版本:Ubuntu 16.04
MySQL版本:5.7.17

安裝方式,通過(guò) MySQL APT 源安裝。(MySQL官網(wǎng)下載)
只要開(kāi)啟二進(jìn)制日志 log-bin 選項(xiàng),就啟動(dòng)失敗,而且在 mysql 自己的錯(cuò)誤日志里面沒(méi)有日志信息。

問(wèn)題復(fù)現(xiàn):

安裝好 MySQL 后,以默認(rèn)配置可以正常啟動(dòng) mysql.

嘗試開(kāi)啟二進(jìn)制日志:log-bin=mysql-bin

啟動(dòng)失敗!

/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!

經(jīng)歷幾小時(shí)查找原因,找到解決辦法,添加如下選項(xiàng)
server-id=1

試了下確實(shí)可以了。

然后回來(lái)看官方文檔是否又說(shuō)明,真的有!

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 版本后,如果要開(kāi)啟二進(jìn)制日志,必須同時(shí)開(kāi)啟 --server-id 選項(xiàng)。
server-id 不要設(shè)置為0(不支持主從復(fù)制),應(yīng)該設(shè)置為 1 或者其他值。

補(bǔ)充

之前奇怪為什么 mysql.err 里面沒(méi)有記錄錯(cuò)誤日志。
今天看到這篇文章:AppArmor and MySQL
https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

才明白或許應(yīng)該去 /var/log/syslog 查看日志。然后嘗試重現(xiàn)昨天的錯(cuò)誤,也就是開(kāi)啟 log-bin 選項(xiàng),但是沒(méi)有開(kāi)啟 server-id 選項(xiàng),然后 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

果然是在這里輸出錯(cuò)誤日志。而且說(shuō)得很明白 you haven't provided the mandatory server-id。

.. 昨天花了那么多時(shí)間在網(wǎng)上找原因..真是一個(gè)教訓(xùn),以后遇到啟動(dòng)時(shí)出問(wèn)題,一定要看看 syslog 的記錄。

還沒(méi)完。

這個(gè)坑可以繞過(guò)去了。但要在 Ubuntu 下定制自己的數(shù)據(jù)目錄,還有一個(gè)坑,這個(gè)坑跟 apparmor 有關(guān)系。

mysql 和 apparmor 就再另開(kāi)一篇博文來(lái)講了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 【MySQL】Linux下MySQL 5.5、5.6和5.7的RPM、二進(jìn)制和源碼安裝 1.1BLOG文檔結(jié)構(gòu)圖 ...
    小麥苗DB寶閱讀 10,900評(píng)論 0 31
  • Redis 配置文件示例 注意:想要讀取配置文件,Redis的第一個(gè)參數(shù)必須是文件的路徑 ./redis-serv...
    起個(gè)名忒難閱讀 1,361評(píng)論 0 1
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,688評(píng)論 19 139
  • Mysql 有4種類型的日志:Error Log、Genaral Query Log、 Binary Log 和 ...
    人在碼途閱讀 16,602評(píng)論 2 11
  • 天漸漸涼,夜越來(lái)越長(zhǎng)。我知道,你喜歡的冬天要來(lái)了。外面起風(fēng)了,風(fēng)拂過(guò)我的臉,它冰冷的指尖掠過(guò)我的發(fā),感覺(jué)不到一絲的...
    嘎嘎蝸牛閱讀 849評(píng)論 3 0

友情鏈接更多精彩內(nèi)容