![与 mariaDB 发生愚蠢冲突后无法安装 MySQL](https://linux22.com/image/1173226/%E4%B8%8E%20mariaDB%20%E5%8F%91%E7%94%9F%E6%84%9A%E8%A0%A2%E5%86%B2%E7%AA%81%E5%90%8E%E6%97%A0%E6%B3%95%E5%AE%89%E8%A3%85%20MySQL.png)
我完全忘记了这台计算机上已经安装了 MySQL,并且我安装了 MariaDB,我也不知道在同一台计算机上安装这两个软件包的后果,我一直在尝试完全卸载这两个安装并删除它们的依赖项。我在网上查找了几个关于如何做到这一点的教程,但我仍然无法运行 MySQL,下面您将找到终端窗口的屏幕截图以及我尝试过的许多解决方案的列表,不幸的是,我尝试了太多次,以至于我无法记住我尝试它们的顺序,我只想要一个可以正常工作的 MySQL 安装,但不知何故,有些东西我无法从以前的安装中删除,MySQL 安装无法正常工作,我收到 dpkg:警告。任何和所有的帮助都将不胜感激。(Ubuntu 20.04)
这是终端窗口的屏幕截图。
homeserver@ubuserv:~/Desktop$ ps ax | grep mysql
4958 pts/0 S+ 0:00 grep --color=auto mysql
homeserver@ubuserv:~/Desktop$ sudo mysql_secure_installation utility
[sudo] password for homeserver:
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
homeserver@ubuserv:~/Desktop$ mysql --version
mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
homeserver@ubuserv:~/Desktop$ sudo systemctl stop mysql
Failed to stop mysql.service: Unit mysql.service not loaded.
homeserver@ubuserv:~/Desktop$ sudo systemctl stop mysql
Failed to stop mysql.service: Unit mysql.service not loaded.
homeserver@ubuserv:~/Desktop$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
homeserver@ubuserv:~/Desktop$ sudo apt install synaptic
Reading package lists... Done
Building dependency tree
Reading state information... Done
synaptic is already the newest version (0.84.6ubuntu5).
The following packages were automatically installed and are no longer required:
hplip-data printer-driver-postscript-hp python3-renderpm
python3-reportlab python3-reportlab-accel
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
homeserver@ubuserv:~/Desktop$ sudo service mysql restart
[sudo] password for homeserver:
Failed to restart mysql.service: Unit mysql.service not found.
homeserver@ubuserv:~/Desktop$ apt search mysql | grep "\[install"
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libdbi-perl/focal,now 1.643-1 amd64 [installed]
libmysqlclient21/focal-updates,focal-security,now 8.0.20-0ubuntu0.20.04.1 amd64 [installed]
librdf0/focal,now 1.0.17-1.1ubuntu1 amd64 [installed,automatic]
mysql-client-8.0/focal-updates,focal-security,now 8.0.20-0ubuntu0.20.04.1 amd64 [installed]
mysql-client-core-8.0/focal-updates,focal-security,now 8.0.20-0ubuntu0.20.04.1 amd64 [installed]
mysql-common/focal,focal,now 5.8+1.0.5ubuntu2 all [installed]
mysql-server/focal-updates,focal-updates,focal-security,focal-security,now 8.0.20-0ubuntu0.20.04.1 all [installed]
mysql-server-8.0/focal-updates,focal-security,now 8.0.20-0ubuntu0.20.04.1 amd64 [installed]
mysql-server-core-8.0/focal-updates,focal-security,now 8.0.20-0ubuntu0.20.04.1 amd64 [installed]
rsyslog/focal,now 8.2001.0-1ubuntu1 amd64 [installed,automatic]
homeserver@ubuserv:~/Desktop$ sudo apt -f install mysql-server
[sudo] password for homeserver:
Reading package lists... Done
Building dependency tree
Reading state information... Done
mysql-server is already the newest version (8.0.20-0ubuntu0.20.04.1).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
homeserver@ubuserv:~/Desktop$ sudo apt -f install mysql-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
mysql-client
0 upgraded, 1 newly installed, 0 to remove and 10 not upgraded.
Need to get 9.424 B of archives.
After this operation, 110 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client all 8.0.20-0ubuntu0.20.04.1 [9.424 B]
Fetched 9.424 B in 1s (14,4 kB/s)
Selecting previously unselected package mysql-client.
dpkg: warning: files list file for package 'mysql-server-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-common' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-server-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-8.0' missing; assuming package has no files currently installed
(Reading database ... 223970 files and directories currently installed.)
Preparing to unpack .../mysql-client_8.0.20-0ubuntu0.20.04.1_all.deb ...
Unpacking mysql-client (8.0.20-0ubuntu0.20.04.1) ...
Setting up mysql-client (8.0.20-0ubuntu0.20.04.1) ...
homeserver@ubuserv:~/Desktop$ dir
homeserver@ubuserv:~/Desktop$ cd ..
homeserver@ubuserv:~$ dir
Desktop Documents Downloads Music Pictures Public snap Templates Videos
homeserver@ubuserv:~$ cd Downloads
homeserver@ubuserv:~/Downloads$ dir
bprocessor-M11.zip ClientBridgeWorking.bin RepeaterBridgeWorking3.bin
ClientBridgeWorking2.bin mysql-apt-config_0.8.15-1_all.deb teamviewer_15.5.3_amd64.deb
homeserver@ubuserv:~/Downloads$ sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
Selecting previously unselected package mysql-apt-config.
dpkg: warning: files list file for package 'mysql-server-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-common' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-server-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-8.0' missing; assuming package has no files currently installed
(Reading database ... 223974 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.15-1_all.deb ...
Unpacking mysql-apt-config (0.8.15-1) ...
Setting up mysql-apt-config (0.8.15-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK
homeserver@ubuserv:~/Downloads$ sudo service mysql status
Unit mysql.service could not be found.
homeserver@ubuserv:~/Downloads$ sudo service mysql start
Failed to start mysql.service: Unit mysql.service not found.
homeserver@ubuserv:~/Downloads$ sudo dpkg -P mysql
dpkg: warning: ignoring request to remove mysql which isn't installed
homeserver@ubuserv:~/Downloads$ sudo apt-get install --reinstall mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 10 not upgraded.
Need to get 9.540 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-server all 8.0.20-0ubuntu0.20.04.1 [9.540 B]
Fetched 9.540 B in 1s (17,6 kB/s)
dpkg: warning: files list file for package 'mysql-server-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-common' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-server-core-8.0' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'mysql-client-8.0' missing; assuming package has no files currently installed
(Reading database ... 223979 files and directories currently installed.)
Preparing to unpack .../mysql-server_8.0.20-0ubuntu0.20.04.1_all.deb ...
Unpacking mysql-server (8.0.20-0ubuntu0.20.04.1) over (8.0.20-0ubuntu0.20.04.1) ...
Setting up mysql-server (8.0.20-0ubuntu0.20.04.1) ...
SU 终端
homeserver@ubuserv:~/Desktop$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
homeserver@ubuserv:~/Desktop$ sudo apt install synaptic
Reading package lists... Done
Building dependency tree
Reading state information... Done
synaptic is already the newest version (0.84.6ubuntu5).
The following packages were automatically installed and are no longer required:
hplip-data printer-driver-postscript-hp python3-renderpm
python3-reportlab python3-reportlab-accel
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
homeserver@ubuserv:~/Desktop$ synaptic
homeserver@ubuserv:~/Desktop$ sudo su
root@ubuserv:/home/homeserver/Desktop# synaptic
root@ubuserv:/home/homeserver/Desktop# gksu synaptic
Command 'gksu' not found, did you mean:
command 'gosu' from deb gosu (1.10-1)
command 'ksu' from deb heimdal-clients (7.7.0+dfsg-1ubuntu1)
command 'ksu' from deb krb5-user (1.17-6ubuntu4)
Try: apt install <deb name>
root@ubuserv:/home/homeserver/Desktop# gksu synaptic
Command 'gksu' not found, did you mean:
command 'ksu' from deb heimdal-clients (7.7.0+dfsg-1ubuntu1)
command 'ksu' from deb krb5-user (1.17-6ubuntu4)
command 'gosu' from deb gosu (1.10-1)
Try: apt install <deb name>
root@ubuserv:/home/homeserver/Desktop# synaptic admin://
root@ubuserv:/home/homeserver/Desktop# xhost +si:localuser:root
localuser:root being added to access control list
root@ubuserv:/home/homeserver/Desktop# synaptic
^C
root@ubuserv:/home/homeserver/Desktop# synaptic
root@ubuserv:/home/homeserver/Desktop# synaptic
root@ubuserv:/home/homeserver/Desktop# synaptic
^C
root@ubuserv:/home/homeserver/Desktop# synaptic
root@ubuserv:/home/homeserver/Desktop# synaptic
root@ubuserv:/home/homeserver/Desktop# cd..
cd..: command not found
root@ubuserv:/home/homeserver/Desktop# cd ..
root@ubuserv:/home/homeserver# cd ..
root@ubuserv:/home# cd ..
root@ubuserv:/# cd ..
root@ubuserv:/# dir
bin dev lib libx32 mnt root snap sys var
boot etc lib32 lost+found opt run srv tmp
cdrom home lib64 media proc sbin swapfile usr
root@ubuserv:/# sudo aptitude install mysql-server
sudo: aptitude: command not found
root@ubuserv:/# sudo apt install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
mysql-server is already the newest version (8.0.20-0ubuntu0.20.04.1).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
root@ubuserv:/#
终端发出的命令
$ sudo apt install mysql-server
$ sudo mysql_secure_installation
$ sudo mysql
$ sudo apt remove mysql-server
$ sudo apt install mariadb-server
$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
$ sudo service mysql restart
$ sudo service mysql stop
$ sudo service mysql start
$ systemctl status mariadb.service
$ set mysql/config/mysqld/innodb_force_recovery=1
$ systemctl start mariadb
$ find /etc -name *.cnf
$ sudo apt-get purge mariadb-server
$ sudo dpkg -l | grep mariadb
$ sudo nano /etc/mysql/debian.cnf
$ sudo mysql_secure_installation
$ apt-get purge mysql-server\*
$ rm -rf /etc/my.cnf /etc/mysql
$ sudo apt-get remove --purge mysql*
$ sudo apt-get purge mysql*
$ sudo apt-get autoclean
$ sudo apt-get remove dbconfig-mysql
$ sudo apt-get remove ––purge mariadb-server
$ del mysql*
$ rm mysql*
$ sudo apt-get clean
$ ps -A|grep mysql
$ sudo pkill mysql
$ ps -A|grep mysqld
$ ps ax | grep mysql
$ sudo nano sources.list
$ sudo apt purge mariadb-*
$ sudo rm -rf /usr/share/mysql/
$ find mariadb.repo
$ find mariadb*
$ apt search mysql | grep "\[install"
$ sudo apt -f install mysql-server
$ sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
以 SU 身份发出的命令
# service mysql stop
# killall -KILL mysql mysqld_safe mysqld
# apt-get --yes purge mysql-server mysql-client
# apt-get --yes autoremove --purge
# apt-get autoclean
# deluser --remove-home mysql
# delgroup mysql
# rm -rf /etc/apparmor.d/abstractions/mysql /etc/apparmor.d/cache/usr.sbin.mysqld /etc/mysql /var/lib/mysql /var/log/mysql* /var/log/upstart/mysql.log* /var/run/mysqld
# updatedb
# rm ~/.mysql_history
# sudo apt-get purge mariadb-server
# sudo dpkg -l | grep mariadb
# sudo apt-get purge mariadb-server
# sudo dpkg -l | grep mariadb
# edit /etc/mysql/mysql.conf.d/mysqld.cnf
# killall -KILL mysql mysqld_safe mysqld
# apt-get --yes purge mysql-server mysql-client
# apt-get --yes autoremove --purge
# apt-get autoclean
# deluser --remove-home mysql
# delgroup mysql
# apt-get remove --purge mariadb
# apt-get remove --purge mariadb*
# sudo rm -rf /etc/mysql/
# sudo apt install mysql-server
# sudo apt-get autoclean && sudo apt-get --force-yes remove mysql-community-server-dbgsym mysql-community-server mysql-server
# xhost +si:localuser:root
# synaptic
更新
我已经从 synaptic 中删除了 Libmysqlclient21,因为它似乎已损坏,尝试从 synaptic 成功卸载 MySQL,然后从 synaptic 重新安装它,但没有成功,显然有一个我找不到的正在运行的 MySQL 进程,这阻止了 mysql-server-8.0 的安装(mysql-client、client-8.0、client-core-8.0、server 和 server-core-8.0 重新安装即可)。下面您将看到屏幕截图 https://pastebin.ubuntu.com/p/pJCxYm5K2w/
还 - -
internal Error, No file name for mysql-server:amd64
答案1
好的,看起来 MySQL APT 存储库提供了mysql-common
卸载所有本机 8.0 版本,但他们建议您不要在这里清除,只需卸载:
sudo apt remove mysql-client-core-8.0 mysql-server-core-8.0 mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
然后您就可以进行安装了:
sudo apt install --reinstall -o Dpkg::Options::="--force-confmiss" mysql-community-client-core mysql-community-server-core mysql-common mysql-client mysql-server
最后,您可以通过运行以下命令来更新共享库:
sudo apt install libmysqlclient21
这将取代现有的版本。
可以找到可用软件包的列表和更多信息这里。
答案2
我不明白发生了什么,我通过具有完全管理权限的用户帐户远程访问 ubuntu 机器,但这不是安装 ubuntu 时创建的帐户,现在我终于直接访问了计算机并使用原始帐户登录,令我惊讶的是,当我尝试通过 synaptic 卸载所有 MySQL 时,我根本没有收到任何警告或错误,只是为了安全起见,我运行了以下命令
# sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
# sudo apt-get autoremove -y
# rm -rf /etc/mysql
# sudo find / -iname 'mysql*' -exec rm -rf {} \;
# apt --fix-broken install
没有任何错误或警告,因此我启动了 synaptic 并重新安装了 mysql-server(synaptic 负责处理依赖项),安装正确完成。这对我来说毫无意义,因为具有完全管理权限的用户帐户应该具有完全访问权限,但事实就是如此,MySQL 已安装并正在运行