删除了/etc/mysql/...现在无法安装或卸载其他软件

删除了/etc/mysql/...现在无法安装或卸载其他软件

我正在摆弄我的 mysql 安装,并试图用 mariadb-server 安装替换它。使用典型的命令完全删除 mysql 后,我无法删除旧配置。所以在沮丧的时刻,我犯了一个错误,只是 sudo rm -r /etc/ 中的 mysql 文件夹。现在我的问题是,每当我尝试安装任何其他软件或 mysql 时,我都会从 dpkg 收到以下错误:

aniqui@Lenobuntu-Z50-60:/$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  libllvm9 libllvm9:i386 linux-headers-5.4.0-37 linux-headers-5.4.0-37-generic linux-image-5.4.0-37-generic linux-modules-5.4.0-37-generic linux-modules-extra-5.4.0-37-generic
  linux-modules-nvidia-440-5.4.0-37-generic
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 525 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 252879 files and directories currently installed.)
Removing libllvm9:amd64 (1:9.0.1-12) ...
Removing libllvm9:i386 (1:9.0.1-12) ...
Removing linux-headers-5.4.0-37-generic (5.4.0-37.41) ...
Removing linux-headers-5.4.0-37 (5.4.0-37.41) ...
Removing linux-modules-nvidia-440-5.4.0-37-generic (5.4.0-37.41) ...
linux-image-nvidia-5.4.0-37-generic: removing .ko files
Removing linux-modules-extra-5.4.0-37-generic (5.4.0-37.41) ...
Removing linux-image-5.4.0-37-generic (5.4.0-37.41) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.4.0-37-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-40-generic
Found initrd image: /boot/initrd.img-5.4.0-40-generic
Found linux image: /boot/vmlinuz-5.4.0-39-generic
Found initrd image: /boot/initrd.img-5.4.0-39-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 10 on /dev/sda1
done
Removing linux-modules-5.4.0-37-generic (5.4.0-37.41) ...
Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
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
Processing triggers for libc-bin (2.31-0ubuntu9) ...
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

显然 mysql 仍然安装着,但是由于我删除了 mysql 文件夹,所以我无法继续执行任何其他任务。

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
maniqui@Lenobuntu-Z50-60:/$ mysql --version
mysql  Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
maniqui@Lenobuntu-Z50-60:/$ 

有没有办法清理 dpkg 列表?为了忽略丢失的安装程序?我已经尝试了典型的命令:

apt-get autoremove
apt-get autoclean
apt-get purge
dpkg -r mysql-server-8.0
apt-get install -f

我一直收到错误。 处理时遇到错误:mysql-server-8.0 E:子进程 /usr/bin/dpkg 返回错误代码 (1)

感谢您的帮助! :)

答案1

我已经修复了这个问题。源代码在这里:dpkg 返回错误代码 1

方法 4:删除有问题的包的 post 信息文件,这个方法帮助我解决了这个问题。

sudo mv /var/lib/dpkg/info/mysql-* /tmp
sudo apt-get autoremove

相关内容