完全删除 Ubuntu 14.04 LTS 上的 MySQL

42

我在我的Ubuntu服务器上搞砸了MySQL,无法修复。我已经尝试了每种组合的apt-get remove --purge mysql-serverapt-get autoremoveapt-get purge,并且在Google上搜索了几个小时,但没有任何进展。

我已经彻底放弃了。每次尝试重新安装时都会出现错误。我受够了。我想删除与我的服务器上的MySQL相关的每个文件。

每次尝试重新安装时都会出现这个错误,似乎很常见,但没有一个“解决方法”对我有效。我需要清除系统中与MySQL有关的所有东西。

Unable to set password for the MySQL "root" user                                                                                                        
An error occurred while setting the password for the MySQL administrative user. This may have happened because the account already has a password, or   
because of a communication problem with the MySQL server.                                                                                               
You should check the account's password after the package installation.                                                                                 
Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more information.

请问有没有人能提供一组命令,在我重新安装服务器之前将这个糟糕的数据库从我的系统中清除?

Setting up mysql-server-5.5 (5.5.38-0ubuntu0.14.04.1) ...
140811 10:56:44 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.5 (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 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 previous failure.  
Processing triggers for libc-bin (2.19-0ubuntu6.1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Errors were encountered while processing:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

我已经尝试了所有方法。每个 mysql 文件都被删除了,但它仍然无法正确安装。


请问您能否接受您问题的其中一个答案呢? - Grant
10个回答

93

完全从Ubuntu中删除Mysql:

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

在此之后,如果你重装时遇到问题,请尝试删除以下路径中的Mysql文件:

sudo rm -rf /var/lib/mysql

已经尝试了所有的方法,但仍然有错误。更奇怪的是,如果我执行 find / -name "mysql" 命令,/var/lib/mysql 仍然会出现在结果中,但如果我试图进入该目录,它却不存在... - Warsum
4
删除 /etc/my.cnf 文件,然后重试安装。我遇到了完全相同的问题,这种方法对我奏效了。:-) 希望能帮助其他人。 - ExploringApple
我按照上面的指示成功地重新安装了损坏的Mysql。我不需要从/var/lib/mysql中删除任何文件。当删除脚本询问是否删除底层的phpMyAdmin数据库时,我选择了否。然后我重新安装了mysql-server。之后,在重新安装phpMyAdmin时,当脚本询问是否创建phpMyAdmin数据库时,我选择了否,这是合理的。重启后,一切都完好无损。为了以防万一,我已经备份了所有数据库。 - Kari Kääriäinen
在卸载时,我遇到了一些文件夹不为空的错误。我不得不使用 rm -R troublesome/folder 命令来删除它们。之后,我才能重新安装 MySQL。 - Christopher Leong
@ExploringApple 我需要删除的文件夹是 /etc/mysql/ 而不是文件 /etc/my.cnf。 - Noel Evans

40

在我的Ubuntu 14.04 LTS上,我在MySQL更新后遇到了类似的问题。

我开始收到错误消息:"致命错误:无法打开和锁定特权表:'user'格式不正确"(位于/var/log/mysql/error.log)

MySQL无法启动。

我通过删除以下目录解决了这个问题:/var/lib/mysql/mysql

sudo rm -rf /var/lib/mysql/mysql

这将保留其他与数据库相关的文件,只删除与mysql相关的文件。
执行完以下操作之后:
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

然后重新安装mysql:

sudo apt-get install mysql-server

它完美地运行了。


6
针对仍然存在问题的人提供不同的解决方案。希望我能够帮助那些尝试重新安装Mysql的人。请注意,这是一项搜索和销毁任务,因此要小心谨慎。假设您是超级用户:
apt-get purge mysql*
apt-get purge dbconfig-common #the screen used for mysql password
find / -name *mysql*          #delete any traces of mysql
#insert apt-get cleanups, autoremove,updates etc.

起初,某些残留物干扰了我的mysqlserver-5.5启动。这些命令最终解决了我的问题。


  • 良好的程序设计
  • 一些sys文件没有被删除,但是对于新的安装没有影响。在删除之前,请注意一些mysql目录是否包含您保存的文件!
- cl-r

4
以下内容可以正常工作:
sudo apt-get --purge remove mysql-client mysql-server mysql-common
sudo apt-get autoremove

我必须删除由 dpkg -l | grep mysql 列出的所有软件包,以完全卸载mysql。 - learner

2

使用apt命令卸载并移除所有MySQL软件包:

最初的回答

$ sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
$ sudo apt-get autoremove -y
$ sudo apt-get autoclean

删除MySQL文件夹:

 $ rm -rf /etc/mysql

删除服务器上的所有MySQL文件:

最初的回答
$ sudo find / -iname 'mysql*' -exec rm -rf {} \;

你的系统不应再包含默认的MySQL相关文件。


1

sudo apt-get remove --purge mysql*

完全从目标系统中移除MySQL软件包。

sudo apt-get purge mysql*

删除所有与mysql相关的配置文件。

sudo apt-get autoremove

使用autoremove命令清理未使用的依赖项。

sudo apt-get autoclean

清除目标系统中的所有本地存储库。

sudo apt-get remove dbconfig-mysql

如果您还想删除dbconfig-mysql的本地/配置文件,则可以使用此命令。


0

删除 /etc/my.cnf 文件并重试安装,对于完全相同的问题,这对我有用。 :-)


0

0

删除mysql:

sudo apt -y purge mysql*
sudo apt -y autoremove
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*

重启实例:

sudo shutdown -r now

-1

我之前也遇到过这个问题。结果是,对我来说,mysql已经安装并且正常运行了,只是我不知道如何检查。

$ ps aux | grep mysql

这将向您展示mysql是否已经在运行。如果是,它应该返回类似于这样的内容:

mysql    24294  0.1  1.3 550012 52784 ?        Ssl  15:16   0:06        /usr/sbin/mysqld
gwang    27451  0.0  0.0  15940   924 pts/3    S+   16:34   0:00 grep --color=auto mysql

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接