Skip to content

Instantly share code, notes, and snippets.

@tigawanna
Last active October 13, 2022 06:37
Show Gist options
  • Save tigawanna/07212f5f1f97f4b147f1bc8e0de88a14 to your computer and use it in GitHub Desktop.
Save tigawanna/07212f5f1f97f4b147f1bc8e0de88a14 to your computer and use it in GitHub Desktop.

how to completely remove MySql from linux

i had to do it after i forgot root password and the reset methods wouldn't work

run sudo su first then run

#!/usr/bin/env bash

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: then

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 --

If you re-install mysql afterwards, you may have to run

mkdir /etc/apparmor.d/abstractions/mysql 
mkdir /etc/mysql/conf.d/

credits this thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment