ubuntu下mysql服務重啟失敗解決思路
阿新 • • 發佈:2019-01-03
今天,在遇到ERROR 1290 (HY000): running with the –secure-file-priv錯誤,根據網上提示(參考),在配置檔案my.cnf新增
通過命令 find / -name my.cnf 或者locate my.cnf查詢配置檔案所在位置。
secure_file_priv='/var/lib/mysql-files/'
接著重啟mysql服務,出現提示:
root@vultr:~/weixin/wx# /etc/init.d/mysql restart
[....] Restarting 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.
按照上面提示通過systemctl status mysql.service”或者 “journalctl -xe”檢視
[email protected]:~/weixin/wx# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit -code) since Sat 2018-06-23 06:25:25 UTC;
Process: 19444 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 19428 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, stat
Main PID: 19444 (code=exited, status=1/FAILURE); Control PID: 19445 (mysql-systemd-s)
Tasks: 2 (limit: 4915 )
Memory: 484.0K
CPU: 82ms
CGroup: /system.slice/mysql.service
└─control
├─19445 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─19481 sleep 1
Jun 23 06:25:25 vultr.guest systemd[1]: mysql.service: Service hold-off time over, schedu
Jun 23 06:25:25 vultr.guest systemd[1]: Stopped MySQL Community Server.
Jun 23 06:25:25 vultr.guest systemd[1]: Starting MySQL Community Server...
Jun 23 06:25:25 vultr.guest mysql-systemd-start[19428]: my_print_defaults: [ERROR] Found
Jun 23 06:25:25 vultr.guest mysql-systemd-start[19428]: my_print_defaults: [ERROR] Fatal
Jun 23 06:25:25 vultr.guest mysqld[19444]: mysqld: [ERROR] Found option without preceding
Jun 23 06:25:25 vultr.guest mysqld[19444]: mysqld: [ERROR] Fatal error in defaults handli
Jun 23 06:25:25 vultr.guest systemd[1]: mysql.service: Main process exited, code=exited,
lines 1-22/22 (END)
[email protected]:~/weixin/wx# journalctl -xe
-- Unit mysql.service has failed.
--
-- The result is failed.
Jun 23 06:25:55 vultr.guest systemd[1]: mysql.service: Unit entered failed state.
Jun 23 06:25:55 vultr.guest systemd[1]: mysql.service: Failed with result 'exit-code'.
Jun 23 06:25:56 vultr.guest systemd[1]: mysql.service: Service hold-off time over, schedu
Jun 23 06:25:56 vultr.guest systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has finished shutting down.
Jun 23 06:25:56 vultr.guest systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has begun starting up.
Jun 23 06:25:56 vultr.guest mysql-systemd-start[19524]: my_print_defaults: [ERROR] Found
Jun 23 06:25:56 vultr.guest mysql-systemd-start[19524]: my_print_defaults: [ERROR] Fatal
Jun 23 06:25:56 vultr.guest smbd[19512]: pam_unix(samba:session): session closed for user
Jun 23 06:25:56 vultr.guest mysqld[19540]: mysqld: [ERROR] Found option without preceding
Jun 23 06:25:56 vultr.guest mysqld[19540]: mysqld: [ERROR] Fatal error in defaults handli
Jun 23 06:25:56 vultr.guest systemd[1]: mysql.service: Main process exited, code=exited,
這些錯誤提示看得讓我一臉懵逼,我能怎麼辦?看幾遍也沒啥收穫,ok,往深一步想想系統自帶的log日誌會不會有這寫錯誤,檢視mysql目錄,tail -10 /var/log/mysql/error.log,什麼輸出也沒有。。。那其它日誌是否有記錄這個錯誤,往上一層看,看到syslog,突然想起些什麼。(原來syslog日誌記錄了很多詳細資訊,其中有程序id和正文)
[email protected]:~/weixin/wx# cat /var/log/syslog
Jun 23 06:25:25 vultr systemd[1]: Failed to start MySQL Community Server.
Jun 23 06:25:25 vultr systemd[1]: mysql.service: Unit entered failed state.
Jun 23 06:25:25 vultr systemd[1]: mysql.service: Failed with result 'exit-code'.
Jun 23 06:25:25 vultr systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jun 23 06:25:25 vultr systemd[1]: Stopped MySQL Community Server.
Jun 23 06:25:25 vultr systemd[1]: Starting MySQL Community Server...
Jun 23 06:25:25 vultr mysql-systemd-start[19428]: my_print_defaults: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!
Jun 23 06:25:25 vultr mysql-systemd-start[19428]: my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Jun 23 06:25:25 vultr mysqld[19444]: mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!
Jun 23 06:25:25 vultr mysqld[19444]: mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
Jun 23 06:25:25 vultr systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
看到上面有一句說22行,把這一句翻譯過來大概的意思就是:“my.cnf添加了22行資訊,並沒有在前面找到[mysql]選項”。最後在配置檔案開頭加上[mysqld],重新啟動成功。
總結:
有時候通過特定提示看到的錯誤提示並沒有解決,當然英語好也許一眼看出systemctl status mysql.service或者 journalctl -xe上面的提示。當然方法我相信還是有的,萬能的系統自帶日誌,看著一類日誌,往往更容易查到錯誤提示。