mysql8 无法启动

mysql8 无法启动

在终端我这样做: 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 社区服务器 已加载:已加载(/lib/systemd/system/mysql.service;已启用;供应商预设:已启用)
活动:失败(结果:退出代码)自 2018-10-31 星期三 22:05:05 UTC;4 秒前 文档:man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html 进程:3592 ExecStart=/usr/sbin/mysqld(代码=exited,状态=1/FAILURE) 进程:3542 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre(代码=exited,状态=0/SUCCESS) 主 PID:3592(代码=exited,状态=1/FAILURE) 状态:“SERVER_BOOTING” 错误:13(权限被拒绝)

10 月 31 日 22:05:04 brawn systemd[1]: 正在启动 MySQL 社区服务器... 10 月 31 日 22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.104214Z 0 [系统] [MY-010116] [服务器] /usr/sbin/mysqld 10 月 31 日 22:05:05 brawn mysqld[3592]: mysqld: 未找到文件 './binlog.index' (OS errno 13 - 权限被拒绝) 10 月 31 日 22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.106057Z 0 [错误] [MY-010119] [服务器] 正在中止 10 月 31 日22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.106193Z 0 [系统] [MY-010910] [服务器] /usr/sbin/mysqld 十月 31 22:05:05 brawn systemd[1]: mysql.service: 主进程已退出,代码=已退出,状态=1/FAILURE 十月 31 22:05:05 brawn systemd[1]: mysql.service: 失败,结果为“退出代码”。十月 31 22:05:05 brawn systemd[1]: 无法启动 MySQL 社区服务器。

并且 journalctl -xe 给我:

-- Unit mysql.service has begun starting up.
Oct 31 22:05:04 brawn audit[3591]: AVC apparmor="STATUS" operation="profile_replace" info="same as current profi
Oct 31 22:05:04 brawn kernel: audit: type=1400 audit(1541023504.856:30): apparmor="STATUS" operation="profile_re
Oct 31 22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.104214Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld
Oct 31 22:05:05 brawn mysqld[3592]: mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)
Oct 31 22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.106057Z 0 [ERROR] [MY-010119] [Server] Aborting
Oct 31 22:05:05 brawn mysqld[3592]: 2018-10-31T22:05:05.106193Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld
Oct 31 22:05:05 brawn systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Oct 31 22:05:05 brawn systemd[1]: mysql.service: Failed with result 'exit-code'.
Oct 31 22:05:05 brawn systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mysql.service has failed.
-- 
-- The result is RESULT.
Oct 31 22:05:05 brawn sudo[3512]: pam_unix(sudo:session): session closed for user root

我对 Ubuntu 和 MySql 还很陌生,但我认为这个问题是由于某种原因 MySql 无法再访问“./binlog.index”,我走在正确的轨道上吗?我该如何解决这个问题?

我确实尝试过sudo find / -name binlog.index,结果如下:

/var/lib/mysql/binlog.index

但是我该怎么做呢?需要什么权限?

答案1

我尝试sudo chown -R mysql:mysql /var/lib/mysql授予 mysql 用户对该文件夹的权限,但如果我做错了,请告诉我。

答案2

对我来说,该问题是由我添加到 my.cnf 中的自定义值引起的:

#query_cache_size = 0
#query_cache_type = 0
#query_cache_limit = 2M
#sort_buffer_size = 512K
#read_rnd_buffer_size = 512K
#tmp_table_size = 32M
#max_heap_table_size = 32M
#thread_pool_size = 24M
#innodb_log_file_size = 16M

一旦这些被赞扬了,我就不再有任何问题了。

答案3

这显然是一个 apparmor 问题,意味着您必须编辑 mysql 服务器的 apparmor 配置:

/etc/apparmor.d/usr.sbin.mysqld

它应该是这样的:

    #include <tunables/global>

/usr/sbin/mysqld {
  #include <abstractions/base>
  #include <abstractions/nameservice>
  #include <abstractions/user-tmp>
  #include <abstractions/mysql>
  #include <abstractions/winbind>

# Allow system resource access
  /sys/devices/system/cpu/ r,
  /sys/devices/system/node/ r,
  /sys/devices/system/node/** r,
  /proc/*/status r,
  capability sys_resource,
  capability dac_override,
  capability setuid,
  capability setgid,
  capability sys_nice,

# Allow network access
  network tcp,

  /etc/hosts.allow r,
  /etc/hosts.deny r,

# Allow config access
  /etc/mysql/** r,

# Allow pid, socket, socket lock file access
  /var/run/mysqld/mysqld.pid rw,
  /var/run/mysqld/mysqld.sock rw,
  /var/run/mysqld/mysqld.sock.lock rw,
  /var/run/mysqld/mysqlx.sock rw,
  /var/run/mysqld/mysqlx.sock.lock rw,
  /run/mysqld/mysqld.pid rw,
  /run/mysqld/mysqld.sock rw,
  /run/mysqld/mysqld.sock.lock rw,
  /run/mysqld/mysqlx.sock rw,
  /run/mysqld/mysqlx.sock.lock rw,

# Allow systemd notify messages
  /{,var/}run/systemd/notify w,

# Allow execution of server binary
  /usr/sbin/mysqld mr,
  /usr/sbin/mysqld-debug mr,

# Allow plugin access
  /usr/lib/mysql/plugin/ r,
  /usr/lib/mysql/plugin/*.so* mr,

# Allow error msg and charset access
  /usr/share/mysql/ r,
  /usr/share/mysql/** r,
  /usr/share/mysql-8.0/ r,
  /usr/share/mysql-8.0/** r,

# Allow data dir access
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,

# Allow data files dir access
  /var/lib/mysql-files/ r,
  /var/lib/mysql-files/** rwk,

# Allow keyring dir access
  /var/lib/mysql-keyring/ r,
  /var/lib/mysql-keyring/** rwk,

# Allow log file access
  /var/log/mysql/ r,
  /var/log/mysql/** rw,

# Allow access to openssl config
  /etc/ssl/openssl.cnf r,

  # Site-specific additions and overrides. See local/README for details.
  include <local/usr.sbin.mysqld>
}
  • 检查路径是否与你的 mysql 配置和目录匹配

最后systemctl restart apparmor; systemctl mysql start

相关内容