无法启动 MySQL 社区服务器

无法启动 MySQL 社区服务器

检查 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

答案1

直接运行时控制台上得到的错误mysqld包括:

2019-08-31T12:51:57.597359Z 0 [错误] 无法访问 --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启动,或者(如果您的设置存在其他问题)出现新的不同的错误消息。

答案2

对我来说,我使用 Stacer 之类的工具运行了一些缓存清除操作来释放空间,然后 MySQL 开始出现问题。

先用这个获取一些线索

grep mysql /var/log/syslog | grep ERROR

如果错误提示:无法打开文件‘/var/log/mysql/error.log’进行错误日志记录:没有此文件或目录 那么显然日志文件已被清理。

使用此项首先创建 MySQL 目录并授予 MySQL 使用该文件夹的所有权限。

> sudo mkdir /var/log/mysql
> sudo chown -R mysql:mysql /var/log/mysql
> sudo service mysql restart

此解决方案与 my.cnf 文件无关,并且对数据完全安全。

答案3

检查以下内容。

  1. 检查文件是否存在。
  2. 检查文件权限。
  3. 如果启用了 Selinux,请按照以下步骤进行修复。

    $ semanage fcontext -a -e /var/lib/mysql /var/lib/mysql-files

    $ restorecon -R /var/lib/mysql-files

    确保 /var/lib/mysql 是空的,然后尝试启动服务器:

    $ 服务 mysqld 启动

检查此链接也可能会有帮助https://askubuntu.com/questions/835541/mysql-install-db-on-ubuntu-16-04

相关内容