在 Ubuntu 22.04 上重新安装 MySQL 服务器 8.0

在 Ubuntu 22.04 上重新安装 MySQL 服务器 8.0

我需要使用以下命令清除 MYSQL 安装:

sudo apt remove --purge mysql-server
sudo apt purge mysql-server
sudo apt autoremove
sudo apt autoclean
sudo apt remove dbconfig-mysql

一切似乎都顺利。

尝试重新安装更新文件列表后出现以下错误:

Setting up mysql-server-8.0 (8.0.30-0ubuntu0.22.04.1) ... 
Renaming removed key_buffer and myisam-recover options (if present) 
ERROR: Unable to start MySQL server: 
mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory) 
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/mysql/my.cnf at l
ine 20. 
mysqld: [ERROR] Fatal error in defaults handling. Program aborted! 
Please take a look at https://wiki.debian.org/Teams/MySQL/FAQ for tips on fixing common upgr
ade issues. 
Once the problem is resolved, run apt-get --fix-broken install to retry. 
dpkg: error processing package mysql-server-8.0 (--configure): 
installed mysql-server-8.0 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 pre
vious failure. 
             Errors were encountered while processing: 
mysql-server-8.0 
mysql-server 
E: Sub-process /usr/bin/dpkg returned an error code (1)

我查看了 wiki 链接,没有帮助。我看到三年前在这里发布的一篇类似帖子,按照推荐尝试了“apt install -f”,但还是没有帮助。

答案1

在尝试删除 mysql 之前,请确保已使用将其关闭sudo systemctl stop mysql,然后尝试再次发出命令。

停止 MySQL 服务后,您可以运行systemctl status mysql以确保它已关闭。

如果它有效的话请告诉我。

[其他解决方案]

根据错误消息创建目录。

sudo mkdir -p /etc/mysql/conf.d/

创建一个新mysql.cnf文件并写入[mysql]其中。

echo "[mysql]" | sudo tee /etc/mysql/conf.d/mysql.cnf

并重新配置软件包。

sudo dpkg --configure -a

相关内容