有一段时间我的 MySQL 服务器停止工作了(几个月前我在家里安装了 kubuntu 22.04)
我检查命令:
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@master-at-home:/path# mysql -h 127.0.0.1 -P 3306 -u root
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
root@master-at-home:/path# sudo service mysql start
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
root@master-at-home:/path# systemctl status mysql.service
× mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2024-10-27 09:33:42 EET; 10s ago
Process: 32412 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
CPU: 2ms
master-at-home systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
master-at-home systemd[1]: Stopped MySQL Community Server.
master-at-home systemd[1]: mysql.service: Start request repeated too quickly.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
root@master-at-home:/path# journalctl -xeu mysql.service
░░ The job identifier is 3931 and the job result is done.
master-at-home systemd[1]: Starting MySQL Community Server...
░░ Subject: A start job for unit mysql.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has begun execution.
░░
░░ The job identifier is 3931.
master-at-home mysql-systemd-start[32412]: MySQL configuration not found at /etc/mysql/my.cnf. Please create one.
master-at-home systemd[1]: mysql.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStartPre= process belonging to unit mysql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has finished with a failure.
░░
░░ The job identifier is 3931 and the job result is failed.
master-at-home systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ Automatic restarting of the unit mysql.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
master-at-home systemd[1]: Stopped MySQL Community Server.
░░ Subject: A stop job for unit mysql.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A stop job for unit mysql.service has finished.
░░
░░ The job identifier is 4065 and the job result is done.
master-at-home systemd[1]: mysql.service: Start request repeated too quickly.
master-at-home systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
master-at-home systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mysql.service has finished with a failure.
░░
░░ The job identifier is 4065 and the job result is failed.
我找到了以下行:
master-at-home mysql-systemd-start[32412]: MySQL configuration not found at /etc/mysql/my.cnf. Please create one.
我根本没有 /etc/mysql/ 子目录。我不知道为什么会这样,以及如何在我的操作系统中恢复 /etc/mysql/my.cnf?
uname -a
Linux master-at-home 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
我决定升级我的操作系统但在消息中收到以下错误:
path# sudo apt-get update
Hit:1 https://artifacts.elastic.co/packages/8.x/apt stable InRelease
Hit:2 http://ua.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 https://deb.nodesource.com/node_18.x nodistro InRelease
Hit:5 https://ppa.launchpadcontent.net/giuspen/ppa/ubuntu jammy InRelease
Hit:6 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease
Hit:7 https://ppa.launchpadcontent.net/openswoole/ppa/ubuntu jammy InRelease
Reading package lists... Done
path# sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
php-common php-mcrypt php-mongodb php8.2-mongodb php8.3-mcrypt php8.3-mongodb
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
Setting up elasticsearch (8.15.3) ...
/usr/share/elasticsearch/bin/elasticsearch-env: line 78: source: /etc/default/elasticsearch: is a directory
dpkg: error processing package elasticsearch (--configure):
installed elasticsearch package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-8.0; however:
Package mysql-server-8.0 is not configured yet.
dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
mysql-server-8.0
elasticsearch
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
这些问题有关联吗?如何解决?
我的 SQL 安装已默认,没有任何特定选项......
更新:
path# sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server-8.0:amd64
path# sudo apt install --reinstall mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server:amd64
更新 # 2:
# sudo apt purge mysql-server-8.0 && sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcgi-fast-perl libcgi-pm-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
mysql-server* mysql-server-8.0*
0 upgraded, 0 newly installed, 2 to remove and 6 not upgraded.
3 not fully installed or removed.
After this operation, 1 713 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 288059 files and directories currently installed.)
Removing mysql-server (8.0.28-0ubuntu4) ...
Removing mysql-server-8.0 (8.0.28-0ubuntu4) ...
Setting up elasticsearch (8.15.3) ...
/usr/share/elasticsearch/bin/elasticsearch-env: line 78: source: /etc/default/elasticsearch: is a directory
dpkg: error processing package elasticsearch (--configure):
installed elasticsearch package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
elasticsearch
E: Sub-process /usr/bin/dpkg returned an error code (1)
我仍然根本没有 /etc/mysql/ 子目录。
更新 # 3:
我嘟嘟地退出:
whoami
master
运行命令:
master@master-at-home:path$ sudo apt purge elasticsearch && sudo apt install mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libcgi-fast-perl libcgi-pm-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
elasticsearch*
0 upgraded, 0 newly installed, 1 to remove and 6 not upgraded.
1 not fully installed or removed.
After this operation, 1 179 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 288042 files and directories currently installed.)
Removing elasticsearch (8.15.3) ...
Stopping elasticsearch service... OK
(Reading database ... 286653 files and directories currently installed.)
Purging configuration files for elasticsearch (8.15.3) ...
dpkg: warning: elasticsearch: conffile '/etc/default/elasticsearch' is not a plain file or symlink (= '/etc/default/elasticsearch')
Deleting security auto-configuration directory...OK
dpkg: warning: while removing elasticsearch, directory '/var/lib/elasticsearch' not empty so not removed
dpkg: warning: while removing elasticsearch, directory '/usr/lib/systemd/system' not empty so not removed
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
tinyca
The following NEW packages will be installed:
mysql-server-8.0
0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 0 B/1 386 kB of archives.
After this operation, 1 603 kB of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 286641 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.28-0ubuntu4_amd64.deb ...
grep: /etc/mysql/: No such file or directory
Unpacking mysql-server-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)