3

I want to completely remove MySQL from my system, including databases, settings, logs, journals, etc.

How can I do it?

Update/Note: The MySQL was installed using the following terminal commands:

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation

OS Name: Ubuntu 20.04.1 LTS
OS Mode: Live USB drive with persistent storage
MySQL version: mysql Ver 8.0.20

1
  • 2
    How you uninstall/remove something depends entirely upon how you originally installed it. Please edit your question to include that information
    – user535733
    Aug 25 '20 at 20:09
10

As you already know how you installed it and what version you're working with, you can do the following:

Stop the MySQL service:

sudo systemctl stop mysqld

Purge MySQL, databases, and configurations:

sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*

Remove any additional database files:

sudo rm -rf /var/lib/mysql/

The folder where the configuration was and any stranglers:

sudo rm -rf /etc/mysql/

Clean the logs:

sudo rm -rf /var/log/mysql

Delete the user-generated during installation:

sudo deluser --remove-home mysql

Finally, get rid of the usergroup that was created during installation:

sudo delgroup mysql

That should get rid of everything. If you installed a third-party PPA in order to install MySQL then you'll need to remove that.

sudo add-apt-repository --remove ppa:theppayouused/ppa

And that should be everything related to MySQL and nothing else.

2
  • sudo delgroup mysql returns this message /usr/sbin/delgroup: mysql' still has mysql' as their primary group!
    – BlueSkies
    Sep 3 '20 at 21:21
  • Check less /etc/passwd and see if you have mysql users. If so, you'll need to remove them. Worst case, the existence of the group won't cause any major issues by simply existing.
    – KGIII
    Sep 3 '20 at 21:36
1

This is what I did, in ubuntu terminal i located mysql by typing in

which mysqld

For which I got an output

/usr/sbin/mysql

Further mysql was inside lampp as well, i located it by

mysql -u root -p -h 127.0.0.1 -e "select @@socket"

For which I got an output

/opt/lampp/var/mysql/mysql.sock

Then i typed in

sudo -i

and pressed enter to open as root, after which I typed in and removed mysql in one location

sudo rm -rf /usr/sbin/mysql

Did a restart. and again opened as root in ubuntu terminal and typed in location of mysql inside lampp

sudo rm -rf /opt/lampp/var/mysql/mysql

Again did a system restart.Next in terminal i typed in

mysql

I got the output mysql cannot be located, for reassurance purpose I typed in

which mysqld

No output, mysql has been uninstalled

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.