Ubuntu 16.04 mariaDB 更新后无法正常工作

Ubuntu 16.04 mariaDB 更新后无法正常工作

我在远程服务器上有 mariaDB,每当我输入mysql -u root -p它时都会抛出:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

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.

这是由于更新或升级而发生的。

我正在使用 mariadb,因此/etc/mysql文件夹包含:

conf.d  
debian.cnf
debian-start
mariadb.conf.d
my.cnf
my.cnf.fallback
my.cnf.save
mysql.cnf
mysql.conf.d

更新 :

systemctl status mysql.service返回:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Sun 2017-06-11 08:23:54 UTC; 14s ago
  Process: 30388 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 30380 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 30388 (code=exited, status=1/FAILURE);         : 30391 (mysql-systemd-s)
    Tasks: 2
   Memory: 324.0K
      CPU: 356ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─30391 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─30475 sleep 1

Jun 11 08:23:54 demo systemd[1]: Starting MySQL Community Server...
Jun 11 08:23:54 demo systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

journalctl -xe返回:

Jun 11 08:28:14 demo sshd[31141]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=114.115.215.178  user=www-data
Jun 11 08:28:16 demo sshd[31143]: Failed password for root from 59.63.188.32 port 52862 ssh2
Jun 11 08:28:16 demo sshd[31141]: Failed password for www-data from 114.115.215.178 port 44506 ssh2
Jun 11 08:28:19 demo sshd[31143]: Failed password for root from 59.63.188.32 port 52862 ssh2
Jun 11 08:28:19 demo sshd[31141]: Failed password for www-data from 114.115.215.178 port 44506 ssh2
Jun 11 08:28:21 demo sshd[31141]: Failed password for www-data from 114.115.215.178 port 44506 ssh2
Jun 11 08:28:21 demo sshd[31143]: Failed password for root from 59.63.188.32 port 52862 ssh2
Jun 11 08:28:21 demo sshd[31141]: Connection closed by 114.115.215.178 port 44506 [preauth]
Jun 11 08:28:21 demo sshd[31141]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=114.115.215.178  user=www-data
Jun 11 08:28:22 demo sshd[31143]: Received disconnect from 59.63.188.32 port 52862:11:  [preauth]
Jun 11 08:28:22 demo sshd[31143]: Disconnected from 59.63.188.32 port 52862 [preauth]
Jun 11 08:28:22 demo sshd[31143]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=59.63.188.32  user=root
Jun 11 08:28:34 demo systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Jun 11 08:28:34 demo systemd[1]: mysql.service: Unit entered failed state.
Jun 11 08:28:34 demo systemd[1]: mysql.service: Failed with result 'exit-code'.
Jun 11 08:28:34 demo systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jun 11 08:28:34 demo systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Jun 11 08:28:34 demo systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Jun 11 08:28:34 demo kernel: audit: type=1400 audit(1497169714.604:4579): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/31200/status" pid=31
Jun 11 08:28:34 demo audit[31200]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/31200/status" pid=31200 comm="mysqld" requested_mask="r
Jun 11 08:28:34 demo audit[31200]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=31200 comm="mysqld" requested_
Jun 11 08:28:34 demo audit[31200]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/31200/status" pid=31200 comm="mysqld" requested_mask="r
Jun 11 08:28:34 demo kernel: audit: type=1400 audit(1497169714.608:4580): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/"
Jun 11 08:28:34 demo kernel: audit: type=1400 audit(1497169714.608:4581): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/31200/status" pid=31
Jun 11 08:28:34 demo systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE

答案1

从 Ubuntu 18 LTS 升级到 Ubuntu 20 LTS 后,MariaDB 也出现了类似的问题。就我而言,缺少排序规则导致 mysqld 无法启动。可能是因为在升级过程中被问到是否要保留当前(本地修改的)配置或是否要用最新配置替换它们时,我总是保留本地配置。所以可能这就是新必需值未出现的原因。

无论如何,这就是我发现的方式:

mysqld --help --verbose | grep 'log-error' | tail -1

这向我显示了错误[ERROR] COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'。因此我打开了 mysql 配置:

sudo vim /etc/mysql/my.cnf

collation-server在最底部添加了一行(基于这个 Stack Overflow 回复)所以我的配置如下所示:

...

[mysqld]
character-set-server = utf8
collation-server = utf8_unicode_ci

然后我重新启动了服务,然后 mysqld 又启动了:

sudo service mysqld start

相关内容