81

The answers to related questions forget to:

  • remove the MySQL databases
  • remove the mysql user
  • remove the logs in /var/log

How do I uninstall MySQL completely?

muru
  • 193,181
  • 53
  • 473
  • 722
Olathe
  • 4,200
  • 2
  • 17
  • 24

4 Answers4

180

Building off of another answer, open a terminal (press Ctrl+Alt+T) and run the following:

sudo -i
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
exit

If you want to delete the log of what you did while using the mysql client:

rm ~/.mysql_history

If you want to delete the logs of what all users on the system did while using the mysql client (the other users might be unhappy with this):

awk -F : '{ print($6 "/.mysql_history"); }' /etc/passwd | xargs -r -d '\n' -- sudo rm -f --

or for all logs including those outside of existing user home directories:

sudo find / -name .mysql_history -delete
David Foerster
  • 35,754
  • 55
  • 92
  • 145
Olathe
  • 4,200
  • 2
  • 17
  • 24
  • 26
    You may also need `dpkg -l | grep mysql` to list any installed mysql packages, then e.g. `sudo apt-get purge mysql-common` for each entry – xxjjnn Jul 13 '16 at 08:33
  • 11
    If you re-install mysql afterwards, you may have to run `mkdir /etc/apparmor.d/abstractions/mysql` and `mkdir /etc/mysql/conf.d/` again. – kiltek Mar 06 '17 at 14:17
  • What about /var/lib/mysql/mysql-files and /var/lib/mysql-keyring ? – Dom Jul 15 '20 at 12:36
  • This is very, very risky stuff! Please do only if you're absolutely certain, that you don't need any data from the your mysql anymore. (check additionally `ls -la /var/lib/mysql`) – telenaut Oct 01 '21 at 21:07
  • This completely botched my system... – Hakaishin Oct 13 '21 at 13:20
  • Be careful in WSL something is missing now or something, so any subsequent install or OS upgrade fails. Still trying to figure it out, I don't want to start fresh with WSL. No useful error aside from pointing to mysql server and E: Sub-process /usr/bin/dpkg returned an error code (1) – JimLohse Aug 14 '23 at 23:32
37

I found some help, but it did not remove everything. I added an asterisk before and after mysql like this:

sudo apt-get remove --purge *mysql\*
sudo apt-get autoremove
sudo apt-get autoclean
Zanna
  • 69,223
  • 56
  • 216
  • 327
Foxsolo
  • 387
  • 3
  • 3
1

I used a collab of 2 answers, first I ran this

  • sudo -i

  • 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

  • exit

Then checked, but still had an error, so as backup, I ran this within the terminal.

  • sudo apt-get remove --purge *mysql*
  • sudo apt-get autoremove
  • sudo apt-get autoclean

Worked perfectly.

CMI Guides
  • 11
  • 2
0

Another way, that worked for me, was to use Synamptic Package Manager. On the left hand pane,where it says: All, Installed, etc. there is an entry for Not Installed (residual config.) (or similar wording). Under there I found options to clear all MySQL install files. This worked for MySQL 5.7.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Anthony
  • 9
  • 1