124

I am trying to uninstall mysql from my ubuntu 12.04 completely. But not able to.

I tried a lot of commands. But nothing is working. Can anyone help out here!

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

I am not able to understand what to do. I want to remove everything regarding MySQL. Whenever I am trying to locate it. I am getting that.

I want everything to be removed. mysql-server, mysql-client, mysql-libraries and even configuration.

Please help me!!!

emotality
  • 12,795
  • 4
  • 39
  • 60
user1411472
  • 1,639
  • 3
  • 14
  • 8

3 Answers3

369

First of all, do a backup of your needed databases with mysqldump

Note: If you want to restore later, just backup your relevant databases, and not the WHOLE, because the whole database might actually be the reason you need to purge and reinstall).

In total, do this:

sudo service mysql stop  #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser -f mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.7
sudo apt-get purge mysql-client-core-5.7
sudo rm -rf /var/log/mysql
sudo rm -rf /etc/mysql

All above commands in single line (just copy and paste):

sudo service mysql stop && sudo killall -9 mysql && sudo killall -9 mysqld && sudo apt-get remove --purge mysql-server mysql-client mysql-common && sudo apt-get autoremove && sudo apt-get autoclean && sudo deluser mysql && sudo rm -rf /var/lib/mysql && sudo apt-get purge mysql-server-core-5.7 && sudo apt-get purge mysql-client-core-5.7 && sudo rm -rf /var/log/mysql && sudo rm -rf /etc/mysql
CodeTower
  • 6,293
  • 5
  • 30
  • 54
  • 5
    Before all of this you have to stop the mysql service. "sudo service stop". Otherwise you will get error like "userdel: user mysql is currently logged in". – arulraj.net Aug 04 '14 at 13:31
  • 1
    What about also deleting the user group? – Ty. Sep 30 '14 at 03:59
  • It worked great with tasksel. i couldn't make another password with just removing/adding lamp – Nicolas Zozol Oct 30 '14 at 11:17
  • 10
    For an even more **complete** uninstall, I would also include the removal of configuration and logs: `sudo rm -rf /var/log/mysql` and `sudo rm -rf /etc/mysql` – Chris Mar 15 '15 at 17:59
  • 1
    Confirmed that this also works to remove **MySQL 5.6** (just change the version number in the relevant commands in this answer). – Dan Nissenbaum Oct 09 '15 at 08:34
  • Worked on Ubuntu 14.04.4 LTS with MySQL 5.5 – alfadog67 May 17 '16 at 15:20
  • 1
    Also worked for MariaDB. I had conflicts after installing/removing both, and clearing all MySQL/MariaDB fixed it. (btw, needs to replace `mysql` with `mariadb` in commands) – Balmipour Jan 04 '17 at 11:45
  • 1
    I had to remove packages listed by `dpkg -l | grep mysql` to completely remove mysql – learner Aug 23 '17 at 06:23
  • I found ```sudo deluser mysql``` would report that the user was in use by a process id. You can use ```sudo deluser -f mysql``` to force the user delete in this case, or kill the process with ```kill -p pid``` and then do ```sudo deluser mysql``` – Nick Weavers Mar 18 '18 at 20:19
  • `dpkg -l | grep mysql`, then `dpkg -r mysql-server-8.0` or `dpkg -P mysql-server-8.0` finally did it at the end. – Muhammad Adeel Feb 15 '20 at 06:08
80

You need to remove the /var/lib/mysql folder. Also, purge when you remove the packages (I'm told this helps).

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

sudo rm -rf /var/lib/mysql

I was encountering similar issues. The second line got rid of my issues and allowed me to set up MySql from scratch. Hopefully it helps you too!

Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52
29

Run these commands in the terminal:

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

sudo apt-get autoremove

sudo apt-get autoclean

Run these commands separately as each command requires confirmation & if run as a block, the command below the one currently running will cancel the confirmation (leading to the command not being run).

Please refer to How do I uninstall Mysql?

Community
  • 1
  • 1
E3G
  • 479
  • 5
  • 6