Completely Remove MySQL Ubuntu 14.04 LTS

2019-01-30 02:56发布

问题:

I somehow have messed up my MySQL on my Ubuntu server and cannot fix it. I have tried every single combination of apt-get remove --purge mysql-server, apt-get autoremove, apt-get purge, Googled for hours and nothing.

I have literally given up. Every time I try to reinstall I get error. I've had enough. I want to remove every single file associated with MySQL on my server.

I get this error every time I try to reinstall which seems to be common but not one "fix" has worked for me. I need to clean my system of everything 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.

Please can someone give me a set of command to purge this ungodly database from my system before I do a fresh install of the server.

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)

I have literally tried everything. Every single mysql file is removed and it still will not install properly.

回答1:

To Completly remove Mysql from Ubuntu :

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

after this, if you are having issues with re installing, Try to remove Mysql files in :

sudo rm -rf /var/lib/mysql

Hope this helps .



回答2:

I experienced a similar issue on Ubuntu 14.04 LTS after a MySQL update.

I started getting error: "Fatal error: Can't open and lock privilege tables: Incorrect file format 'user'" in /var/log/mysql/error.log

MySQL could not start.

I resolved it by removing the following directory: /var/lib/mysql/mysql

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

This leaves your other DB related files in place, only removing the mysql related files.

After running these:

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

Then reinstalling mysql:

sudo apt-get install mysql-server

It worked perfectly.



回答3:

Different solution for those still having issues. Hopefully I can help those trying to reinstall Mysql. Note, It's a seek and destroy mission. So be weary. Assuming your root:

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.

Originally, something leftover was interfering with my startup of mysqlserver-5.5. These commands ended up resolving the issue for myself.



回答4:

The following works:

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


回答5:

This is what saved me. Apparently the depackager tries to put things in the wrong tmp folder.

https://askubuntu.com/a/248860



回答6:

Remove /etc/my.cnf file and retry the installation, it worked for me for exactly same problem. :-)



回答7:

sudo apt-get remove --purge mysql*

Remove the MySQL packages fully from the target system.

sudo apt-get purge mysql*

Remove all mysql related configuration files.

sudo apt-get autoremove

Clean up unused dependencies using autoremove command.

sudo apt-get autoclean

To clear all local repository in the target system.

sudo apt-get remove dbconfig-mysql

If you also want to delete your local/config files for dbconfig-mysql then this will work.



回答8:

I just had this same issue. It turns out for me, mysql was already installed and working. I just didn't know how to check.

$ ps aux | grep mysql

This will show you if mysql is already running. If it is it should return something like this:

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


标签: mysql ubuntu lts