Ubuntu

無法啟動 MySQL 社區伺服器

  • July 15, 2021

檢查 my-sql 的狀態時顯示以下錯誤。

作業系統:Ubuntu 18.04.3

Mysql:mysql Ver 14.14 Distrib 5.7.27,適用於 Linux (x86_64),使用 EditLine 包裝器

mysql.service - MySQL Community Server
  Loaded: loaded (/lib/systemd/system/mysql.service; bad; vendor preset: enabled)
  Active: failed (Result: exit-code) since Sat 2019-08-31 08:27:11 CEST; 1min 12s ago
 Process: 18000 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)

Aug 31 08:27:11 myserver systemd[1]: mysql.service: Control process exited, code=exited status=1
Aug 31 08:27:11 myserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Aug 31 08:27:11 myserver systemd[1]: Failed to start MySQL Community Server.
Aug 31 08:27:11 myserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Aug 31 08:27:11 myserver systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Aug 31 08:27:11 myserver systemd[1]: Stopped MySQL Community Server.
Aug 31 08:27:11 myserver systemd[1]: mysql.service: Start request repeated too quickly.
Aug 31 08:27:11 myserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Aug 31 08:27:11 myserver systemd[1]: Failed to start MySQL Community Server.

我嘗試開始使用以以下錯誤結束的 mysqld 命令

mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2019-08-31T12:51:57.596969Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-31T12:51:57.597359Z 0 [ERROR] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2019-08-31T12:51:57.597485Z 0 [ERROR] Aborting

2019-08-31T12:51:57.597607Z 0 [Note] Binlog end

我的.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

直接執行時在控制台上遇到的錯誤mysqld包括:

2019-08-31T12:51:57.597359Z 0

$$ ERROR $$無法訪問 –secure-file-priv 的目錄。請確保該目錄存在並且可以被 MySQL 伺服器訪問。提供的值:/var/lib/mysql-files

那是你的問題。

要解決它,首先檢查您mysqld嘗試執行的使用者;這將是預設 Debian 安裝中的使用者“mysql”(我假設它應該與 Ubuntu 相同);要驗證這一點,請檢查/etc/mysql/my.cnf並查找“user = xxx”行。

一旦您知道使用者mysqld正在嘗試以什麼身份執行,請檢查該目錄是否/var/lib/mysql-files存在(sudo mkdir /var/lib/mysql-files如果不存在)並且歸使用者mysqld執行身份所有(sudo chown mysql /var/lib/mysql-files如果不存在;將chown命令中的“mysql”替換為正確的使用者名如果您配置為以其他使用者身份執行)。

然後再試sudo mysqld一次,您應該可以成功mysqld啟動,或者(如果您的設置存在其他問題)一個新的和不同的錯誤消息。

引用自:https://serverfault.com/questions/981403