无法在 Linux Debian 9 上启动 mysql 服务器

无法在 Linux Debian 9 上启动 mysql 服务器

我尝试了数百个命令来解决这个问题但都无济于事。

当我尝试运行 mysql 服务时出现此错误:

root@lander:/# systemctl status mariadb.service
● mariadb.service - MariaDB 10.1.45 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2020-09-26 21:39:19 CST; 9min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 26857 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"
      CPU: 244ms

Sep 26 21:39:16 lander systemd[1]: Starting MariaDB 10.1.45 database server...
Sep 26 21:39:16 lander mysqld[26857]: 2020-09-26 21:39:16 140169480011136 [Note] /usr/sbin/mysqld (mysqld 10.1.45-MariaD
Sep 26 21:39:19 lander systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Sep 26 21:39:19 lander systemd[1]: Failed to start MariaDB 10.1.45 database server.
Sep 26 21:39:19 lander systemd[1]: mariadb.service: Unit entered failed state.
Sep 26 21:39:19 lander systemd[1]: mariadb.service: Failed with result 'exit-code'.

我认为主要错误是这个,但无法处理它: MySQL -Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Linux 版本:

root@lander:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

MySql 版本:

root@lander:/# mysql --version
mysql  Ver 15.1 Distrib 10.1.45-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

编辑 我搜索了错误的套接字文件,因为它不存在于错误的路径中:

root@lander:/# cd /var/run/mysqld
root@lander:/var/run/mysqld# ls
root@lander:/var/run/mysqld# cd ..
root@lander:/var/run# cd ..
root@lander:/var# cd ..
root@lander:/# find / -name 'mysqld.sock'
/var/lib/docker/overlay2/ab77f131581b7a77915ac3da0112d8fab3a6956f81f7f09b13fec07759bc3756/diff/run/mysqld/mysqld.sock
/var/lib/docker/overlay2/ab77f131581b7a77915ac3da0112d8fab3a6956f81f7f09b13fec07759bc3756/merged/run/mysqld/mysqld.sock
/var/lib/docker/overlay2/ef28c7d5507d3b888ceaf8e79b53a865e16c10c5bea46789e138ac2ff562195f/diff/run/mysqld/mysqld.sock
/var/lib/docker/overlay2/ef28c7d5507d3b888ceaf8e79b53a865e16c10c5bea46789e138ac2ff562195f/merged/run/mysqld/mysqld.sock
root@lander:/#    

编辑2

/etc/mysql/my.cnf 的内容

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# 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.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

编辑3

日志记录“journalctl -u mysql”:

root@lander:/# journalctl -u mysql
-- Logs begin at Wed 2019-07-10 18:31:14 CST, end at Sat 2020-09-26 22:48:51 CST. --
Sep 24 18:36:07 lander systemd[1]: Starting MySQL Community Server...
Sep 24 18:36:07 lander su[2785]: Successful su for mysql by root
Sep 24 18:36:07 lander su[2785]: + ??? root:mysql
Sep 24 18:36:07 lander su[2785]: pam_unix(su:session): session opened for user mysql by (uid=0)
Sep 24 18:36:07 lander mysql-systemd-start[2750]: 2020-09-24T10:36:07.857850Z 0 [Warning] TIMESTAMP with implicit DEFAUL
Sep 24 18:36:07 lander mysql-systemd-start[2750]: 2020-09-24T10:36:07.859745Z 0 [ERROR] --initialize specified but the d
Sep 24 18:36:07 lander mysql-systemd-start[2750]: 2020-09-24T10:36:07.860817Z 0 [ERROR] Aborting
Sep 24 18:36:10 lander systemd[1]: mysql.service: Control process exited, code=exited status=1
Sep 24 18:36:10 lander systemd[1]: Failed to start MySQL Community Server.
Sep 24 18:36:10 lander systemd[1]: mysql.service: Unit entered failed state.
Sep 24 18:36:10 lander systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 24 18:36:10 lander systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 24 18:36:10 lander systemd[1]: Stopped MySQL Community Server.
Sep 24 18:36:10 lander systemd[1]: Starting MySQL Community Server...
Sep 24 18:36:10 lander su[2898]: Successful su for mysql by root
Sep 24 18:36:10 lander su[2898]: + ??? root:mysql
Sep 24 18:36:10 lander su[2898]: pam_unix(su:session): session opened for user mysql by (uid=0)
Sep 24 18:36:10 lander mysql-systemd-start[2863]: 2020-09-24T10:36:10.550368Z 0 [Warning] TIMESTAMP with implicit DEFAUL
Sep 24 18:36:10 lander mysql-systemd-start[2863]: 2020-09-24T10:36:10.551842Z 0 [ERROR] --initialize specified but the d
Sep 24 18:36:10 lander mysql-systemd-start[2863]: 2020-09-24T10:36:10.552828Z 0 [ERROR] Aborting
Sep 24 18:36:12 lander systemd[1]: mysql.service: Control process exited, code=exited status=1
Sep 24 18:36:12 lander systemd[1]: Failed to start MySQL Community Server.
Sep 24 18:36:12 lander systemd[1]: mysql.service: Unit entered failed state.
Sep 24 18:36:12 lander systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 24 18:36:12 lander systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 24 18:36:12 lander systemd[1]: Stopped MySQL Community Server.
Sep 24 18:36:12 lander systemd[1]: Starting MySQL Community Server...
Sep 24 18:36:12 lander su[2986]: Successful su for mysql by root
Sep 24 18:36:12 lander su[2986]: + ??? root:mysql
Sep 24 18:36:12 lander su[2986]: pam_unix(su:session): session opened for user mysql by (uid=0)
Sep 24 18:36:12 lander mysql-systemd-start[2951]: 2020-09-24T10:36:12.782020Z 0 [Warning] TIMESTAMP with implicit DEFAUL
Sep 24 18:36:12 lander mysql-systemd-start[2951]: 2020-09-24T10:36:12.783822Z 0 [ERROR] --initialize specified but the d
Sep 24 18:36:12 lander mysql-systemd-start[2951]: 2020-09-24T10:36:12.785301Z 0 [ERROR] Aborting
Sep 24 18:36:14 lander systemd[1]: mysql.service: Control process exited, code=exited status=1
Sep 24 18:36:14 lander systemd[1]: Failed to start MySQL Community Server.
Sep 24 18:36:14 lander systemd[1]: mysql.service: Unit entered failed state.
Sep 24 18:36:14 lander systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 24 18:36:14 lander systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 24 18:36:14 lander systemd[1]: Stopped MySQL Community Server.
Sep 24 18:36:14 lander systemd[1]: Starting MySQL Community Server...
Sep 24 18:36:14 lander su[3074]: Successful su for mysql by root
Sep 24 18:36:14 lander su[3074]: + ??? root:mysql

答案1

根据 Lukas Räpple 的评论,我试图停止所有docker容器

docker stop $(docker ps -aq)

然后我删除了,因为我不需要它们

 docker rm $(docker ps -aq)

这可能是 mysql 无法通过以下方式启动的原因

/etc/init.d/mysql start

此后,一切顺利。

相关内容