繁体   English   中英

无法启动 MySQL 服务 (Fedora Linux)

[英]Not able to start MySQL Service (Fedora Linux)

我正在学习 Web 开发并尝试为 Spring 引导应用程序设置 MySql 数据库。 我无法创建 MySql 数据库。

我使用以下方式下载了 mysql:

sudo dnf install mysql-community-server

然后我得到以下错误:

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)


$ mysql --version
mysql  Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)

$ sudo service mysql start
Redirecting to /bin/systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service not found.


$ sudo systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details.


$ systemctl status mysqld.service
× mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Wed 2022-11-30 06:22:00 IST; 4s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 3783 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    Process: 3818 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
   Main PID: 3818 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete"
      Error: 22 (Invalid argument)
        CPU: 1.043s

Nov 30 06:21:59 fedora systemd[1]: Starting mysqld.service - MySQL Server...
Nov 30 06:22:00 fedora systemd[1]: mysqld.service: Main process exited, code=exited, status=1/FAILURE
Nov 30 06:22:00 fedora systemd[1]: mysqld.service: Failed with result 'exit-code'.
Nov 30 06:22:00 fedora systemd[1]: Failed to start mysqld.service - MySQL Server.
Nov 30 06:22:00 fedora systemd[1]: mysqld.service: Consumed 1.043s CPU time.



我对 mysql 没有太多经验,所以我无法解决这个错误。 这个 [https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run] 没有解决问题。 重新安装 mysql(多次)并重新启动我的笔记本电脑也无济于事。

$ cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/run/mysqld/mysqld.pid

$ cat /etc/mysql/my.cnf
cat: /etc/mysql/my.cnf: No such file or directory

$ cat /var/lib/mysql/my.cnf
cat: /var/lib/mysql/my.cnf: No such file or directory



编辑:

 $ journalctl -xeu mysqld.service ░░ Defined-By: systemd ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel ░░ ░░ An ExecStart= process belonging to unit mysqld.service has exited. ░░ ░░ The process' exit code is 'exited' and its exit status is 1. Nov 30 06:22:00 fedora systemd[1]: mysqld.service: Failed with result 'exit-code'. ░░ Subject: Unit failed ░░ Defined-By: systemd ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel ░░ ░░ The unit mysqld.service has entered the 'failed' state with result 'exit-code'. Nov 30 06:22:00 fedora systemd[1]: Failed to start mysqld.service - MySQL Server. ░░ Subject: A start job for unit mysqld.service has failed ░░ Defined-By: systemd ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel ░░ ░░ A start job for unit mysqld.service has finished with a failure. ░░ ░░ The job identifier is 3531 and the job result is failed. Nov 30 06:22:00 fedora systemd[1]: mysqld.service: Consumed 1.043s CPU time. ░░ Subject: Resources consumed by unit runtime ░░ Defined-By: systemd ░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel ░░ ░░ The unit mysqld.service completed and consumed the indicated resources.

编辑:记录@/var/log/mysql*.log

 2022-11-30T00:44:42.089067Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 1064 2022-11-30T00:44:42.091892Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2022-11-30T00:44:42.091960Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2022-11-30T00:44:42.092006Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:44:42.092083Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL. 2022-11-30T00:44:42.331797Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 1069 2022-11-30T00:44:42.339299Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2d9a3bde-7048-11ed-a7cd-f406413544b8. 2022-11-30T00:44:42.342844Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory. 2022-11-30T00:44:42.342942Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed. 2022-11-30T00:44:42.342960Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:44:42.343234Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL. 2022-11-30T00:49:37.543811Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 3714 2022-11-30T00:49:37.544916Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2022-11-30T00:49:37.544934Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2022-11-30T00:49:37.545003Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:49:37.545083Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL. 2022-11-30T00:49:37.768975Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 3719 2022-11-30T00:49:37.773567Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory. 2022-11-30T00:49:37.773672Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed. 2022-11-30T00:49:37.773705Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:49:37.774047Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL. 2022-11-30T00:52:00.113630Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 3813 2022-11-30T00:52:00.114677Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2022-11-30T00:52:00.114695Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2022-11-30T00:52:00.114738Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:52:00.114840Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL. 2022-11-30T00:52:00.358242Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 3818 2022-11-30T00:52:00.362438Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory. 2022-11-30T00:52:00.362537Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed. 2022-11-30T00:52:00.362566Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-11-30T00:52:00.362844Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.

有人可以告诉我如何解决这个问题吗?

所以下面应该清理/var/lib/mysql ,然后 mysql 应该能够在启动时干净地重新初始化。 但是,这将删除任何现有数据库,包括用户及其权限:

sudo systemctl stop mysqld
sudo rm -rf /var/lib/mysql/
sudo mkdir -p /var/lib/mysql/
sudo chown -R mysql: /var/lib/mysql/
sudo systemctl start mysqld

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM