Linux
無法在 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
根據 Lukas Räpple 的評論,我試圖停止所有 docker 容器
docker stop $(docker ps -aq)
然後我刪除了,因為我不需要它們
docker rm $(docker ps -aq)
這可能是mysql無法啟動的原因
/etc/init.d/mysql start
之後,它沒有問題地工作。