无法在 Ubuntu 20.04 上运行/卸载/重新安装 mysql

无法在 Ubuntu 20.04 上运行/卸载/重新安装 mysql

在常规升级 Ubuntu 20.04 后,我无法再次运行 mysql。我收到此错误。

xxx@xxx:/etc/mysql$ mysql  

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我尝试了各种组合大约 5 个小时,但都没有奏效。如果当前的数据库还存在的话,我很乐意摆脱它们。

这是我尝试卸载 mysql 服务器时得到的结果:

xxxx@xxx:/etc/mysql$ sudo apt remove mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-server' is not installed, so not removed
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-8.0 (8.0.25-0ubuntu0.20.04.1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
mysqld will log errors to /var/log/mysql/error.log
2021-06-11T12:46:36.625455Z 0 [ERROR] [MY-010946] [Server] Failed to start mysqld daemon. Check mysqld error log.
Warning: Unable to start the server.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error processing package mysql-server-8.0 (--configure):
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

上面显示的 /var/log/mysql/error.log 文件的输出如下:

2021-06-11T12:39:33.378397Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds inste>
2021-06-11T12:39:33.379542Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25-0ubuntu0.20.04.1) starting as process 9109
2021-06-11T12:39:33.380367Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future>
2021-06-11T12:39:33.608401Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-11T12:39:33.629330Z 1 [ERROR] [MY-012263] [InnoDB] The Auto-extending innodb_system data file './ibdata1' is of a different size 768 pages (rounded down to MB) than specified in the>
2021-06-11T12:39:33.629486Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2021-06-11T12:39:34.129573Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2021-06-11T12:39:34.129950Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-06-11T12:39:34.130270Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-06-11T12:39:34.131554Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.25-0ubuntu0.20.04.1)  (Ubuntu).

以下命令输出:

非常感谢你在这方面的帮助。我不想再重新安装 Ubuntu。

谢谢。

答案1

最后我终于成功彻底卸载了。

首先,通过运行以下命令检查是否有任何活动的 mysql 相关服务:

ls /etc/systemd/system

我已将 mysqld.service 和 mysql.service 激活,我可以通过运行以下命令来删除它们

systemctl disable mysqld.service
systemctl daemon-reload
systemctl reset-failed

以上命令请参考:https://superuser.com/questions/513159/how-to-remove-systemd-services

然后我最终运行完全删除 mysql:

sudo apt --purge remove mysql-common

注意:如果遇到以下错误:

update-alternatives: error: alternative path  /etc/mysql/my.cnf.fallback doesn't exist

您可以创建如下符号链接:

 sudo ln -s /etc/mysql/my.cnf /etc/alternatives/my.cnf

现在,如果您已经删除了文件夹 /etc/mysql,没问题,请再次创建它并使用以下命令创建一个名为 my.cnf 的虚拟文件:

sudo touch /etc/mysql/my.cnf

相关内容