Ubuntu 16.04 上的 MySQL 問題

Ubuntu 16.04 上的 MySQL 問題

它昨天隨機壞了(不再啟動),我不知道如何修復它。

當我跑步時:

sudo service mysql start

它給出了這個錯誤:

Job 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

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)<br>
   Active: inactive (dead) (Result: exit-code) since Mon 2016-09-05 15:10:31 CEST; 43s ago<br>
  Process: 6515 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)<br>
Sep 05 15:10:31 vps310084 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.<br>
Sep 05 15:10:31 vps310084 systemd[1]: Stopped MySQL Community Server.<br>
Sep 05 15:10:31 vps310084 systemd[1]: mysql.service: Start request repeated too quickly.<br>
Sep 05 15:10:31 vps310084 systemd[1]: Failed to start MySQL Community Server.<br>
Sep 05 15:10:33 vps310084 systemd[1]: mysql.service: Start request repeated too quickly.<br>
Sep 05 15:10:33 vps310084 systemd[1]: Failed to start MySQL Community Server.

輸出journalctl -xe

Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel**
--
-- Unit mysql.service has failed.
--
-- The result is failed. 
Sep 05 15:14:56 vps310084 systemd[1]: mysql.service: Unit entered failed state. 
Sep 05 15:14:56 vps310084 systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 05 15:14:56 vps310084 systemd[1]: mysql.service: Service hold-off time over, scheduling restart. 
Sep 05 15:14:56 vps310084 systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down<br>
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down. 
Sep 05 15:14:56 vps310084 systemd[1]: mysql.service: Start request repeated too quickly. 
Sep 05 15:14:56 vps310084 systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
--
-- Unit mysql.service has failed.
--
-- The result is failed.

答案1

Mysql 的 systemctl 啟動腳本無法執行此指令 /usr/share/mysql/mysql-systemd-start pre

除了使用以下 shell 程式碼對您的環境進行健全性檢查之外,這並沒有做太多事情:

sanity () {
  if [ ! -r /etc/mysql/my.cnf ]; then
    echo "MySQL configuration not found at /etc/mysql/my.cnf. Please create one."
    exit 1
  fi

  if [ ! -d /var/lib/mysql ] && [ ! -L /var/lib/mysql ]; then
    echo "MySQL data dir not found at /var/lib/mysql. Please create one."
    exit 1
  fi

  if [ ! -d /var/lib/mysql/mysql ] && [ ! -L /var/lib/mysql/mysql ]; then
    echo "MySQL system database not found. Please run mysql_install_db tool."
    exit 1
  fi
}

如果您直接透過 sudo 運行它,您應該會收到這些錯誤訊息之一,請按照其建議並重試,直到它起作用。

這不是隨機損壞,而是缺少文件,請檢查 root 使用者和任何可以 sudo 的使用者的 bash_history。

相關內容