How do I uninstall MySQL completely?

378,757

Solution 1

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

Solution 2

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
Share:
378,757

Related videos on Youtube

Olathe
Author by

Olathe

Updated on September 18, 2022

Comments

  • Olathe
    Olathe almost 2 years

    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?

  • xxjjnn
    xxjjnn almost 8 years
    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
  • George Udosen
    George Udosen over 7 years
    Are you trying to answer the question ?
  • kiltek
    kiltek over 7 years
    If you re-install mysql afterwards, you may have to run mkdir /etc/apparmor.d/abstractions/mysql and mkdir /etc/mysql/conf.d/ again.
  • TryHarder
    TryHarder over 6 years
    I would also sudo rm -rf /var/lib/mysql If I didn't do that, I ran into trouble when re-provisioning the server (using geerlingguy's ansible-role-mysql).
  • Jaber Al Nahian
    Jaber Al Nahian over 5 years
    It also removes php mysqli extension
  • Nadjib Mami
    Nadjib Mami about 5 years
    CAUTION: this may remove a bunch of other packages that any link to MySQL, read carefully what will be removed.
  • Dom
    Dom almost 4 years
    What about /var/lib/mysql/mysql-files and /var/lib/mysql-keyring ?
  • telenaut
    telenaut over 2 years
    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)
  • Hakaishin
    Hakaishin over 2 years
    This completely botched my system...
  • mike rodent
    mike rodent about 2 years
    Why ON EARTH are you assuming a non-deb system? Ludicrous.
  • Admin
    Admin about 2 years
    This is identical to apt purge <package> and it does not remove any of the three things the OP asked how to remove.
  • Admin
    Admin about 2 years
    This does not remove any of the three things the OP asked how to remove in the question. It does not remove the databases, it doesn't remove the logs, and it doesn't remove the mysql user.