无法在 ubuntu 22.04 LTS 上安装 mysql-server

abh*_*jit 10 server mysql software-installation 22.04

我正在尝试在 ubuntu 22.04 LTS 上安装 mysql-server,但收到以下 dpkg 错误消息。我该如何解决这个问题?

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
 mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-ore-8.0
Suggested packages:
 mailx tinyca
The following NEW packages will be installed:
 mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 6 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/21.1 MB of archives.
After this operation, 182 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 201995 files and directories currently installed.)
Preparing to unpack .../mysql-common_1%3a10.5.15+maria~focal_all.deb ...
Unpacking mysql-common (1:10.5.15+maria~focal) ...
Selecting previously unselected package mysql-client-core-8.0.
Preparing to unpack .../mysql-client-core-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-client-core-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-client-8.0.
Preparing to unpack .../mysql-client-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-client-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-server-core-8.0.
Preparing to unpack .../mysql-server-core-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-server-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-common (1:10.5.15+maria~focal) ...
Selecting previously unselected package mysql-server-8.0.
(Reading database ... 202191 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.28-0ubuntu4_amd64.deb ...
Unpacking mysql-server-8.0 (8.0.28-0ubuntu4) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_8.0.28-0ubuntu4_all.deb ...
Unpacking mysql-server (8.0.28-0ubuntu4) ...
Setting up mysql-client-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-core-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-client-8.0 (8.0.28-0ubuntu4) ...
Setting up mysql-server-8.0 (8.0.28-0ubuntu4) ...
/var/lib/dpkg/info/mysql-server-8.0.postinst: line 194: /usr/share/mysql- 
common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 127
No apport report written because the error message indicates its a followup error from a previous failure.
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
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
 mysql-server-8.0
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

尽管运行命令mysqld -V命令会产生以下输出 -

/usr/sbin/mysqld Ver 8.0.28-0ubuntu4 适用于 x86_64 上的 Linux ((Ubuntu))

执行该命令sudo service mysql start会产生以下错误代码 -

mysql.service 作业失败,因为控制进程退出并出现错误代码。有关详细信息,请参阅“systemctl status mysql.service”和“journalctl -xeu mysql.service”。

aqu*_*lla 13

在这里重新发布我对类似问题的回答。我能够使用arief21对20.04上类似问题的解决方案在Ubuntu 22.04上解决这个问题,该解决方案本身是从这里复制的。

概述

问题似乎来自于第一次安装失败后文件系统中残留的一些部分初始化。因此,解决方案基本上是确保清除在失败的安装尝试期间添加或修改的所有内容。

我没有时间更深入地研究,所以我不知道到底是哪些文件应该受到指责,但如果有人可以提供更多见解,请在下面评论,以供未来需要更精致解决方案的读者使用。

清除相关包

  • 确保 MySQL 没有运行:
sudo systemctl stop mysql
Run Code Online (Sandbox Code Playgroud)
  • 然后清除所有 MySQL 包:
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
Run Code Online (Sandbox Code Playgroud)
  • 然后删除所有 MySQL 文件:
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql
Run Code Online (Sandbox Code Playgroud)
  • 最后清理掉所有不需要的包:
sudo apt autoremove
sudo apt autoclean
Run Code Online (Sandbox Code Playgroud)
  • 在继续之前重新启动也没什么坏处
sudo reboot
Run Code Online (Sandbox Code Playgroud)

现在,随着所有残留的配置被剔除,您应该能够再次运行安装命令。

MySQL Apt 包注释

我还在这里读到,有些人在安装 Jammy 时遇到问题mysql-server,建议安装特定的mysql-server-8.0软件包mysql-server-core-8.0。不能 100% 确定这一点的真实性,因为我mysql-server在完全清除后没有再次尝试元包。

sudo apt install mysql-server-core-8.0 mysql-server-8.0
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!