我正在学习Web开发,并试图为Sping Boot 应用程序设置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-hy 000-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.
有人能告诉我怎么修吗?
1条答案
按热度按时间7kjnsjlb1#
所以下面的代码应该可以清理
/var/lib/mysql
,然后mysql应该可以在启动时干净地重新初始化。但是这将删除所有现有的数据库,包括用户和他们的权限: