检查 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
包括:那是你的问题。
要解决它,首先检查您
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
启动,或者(如果您的设置存在其他问题)一个新的和不同的错误消息。对我来说,我使用 Stacer 等工具运行了一些缓存清除操作以释放空间,然后 MySQL 开始出现问题。
使用它首先获得一些线索
如果错误说,无法打开文件'/var/log/mysql/error.log'进行错误记录:没有这样的文件或目录 ,那么很明显,日志文件已被清理。
使用它首先创建 MySQL 目录并授予 MySQL 使用该文件夹的所有权限。
此解决方案与 my.cnf 文件无关,对数据完全安全。
检查下面。
如果启用了 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