How to fully remove MySQL and phpMyAdmin

21,454

Solution 1

You can fully remove MySQL and phpMyAdmin by doing the following:

  1. Open your terminal (CTRL+ALT+T) and log in as root:

    sudo su
  2. Stop all MySql services that may still be running:

    service mysql stop
  3. Remove mysql and all its folders and files:

    apt-get remove --purge mysql*
    
    apt-get remove --purge mysql-server mysql-client mysql-common -y
    
    apt-get autoremove -y
    
    apt-get remove dbconfig-mysql
    
    rm -rf /etc/mysql /var/lib/mysql
    
    find / -iname 'mysql*' -exec rm -rf {} \;
  4. Remove PhpMyAdmin:

    apt-get purge phpmyadmin*
  5. Autoremove and clean all dependencies:

    apt-get autoremove && apt-get autoclean 

Solution 2

If that was a production server, removing everything wouldn't be a solution. Probably your problem is related to the debian-sys-maint MySQL user - its password or its privileges. The correct solution for this issue is provided in this answer on Stack Overflow:

That’s because Debian has a MySQL account debian-sys-maint used for switching on/off and checking status. The password for that user should be the same as stored in /etc/mysql/debian.cnf. The file looks like this:

    # Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host     = localhost
    user     = debian-sys-maint
    password = <password>
    socket   = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    host     = localhost
    user     = debian-sys-maint
    password = <password>
    socket   = /var/run/mysqld/mysqld.sock
    basedir  = /usr

If the password doesn't match (for example because you changed it manually) the init script won't work anymore. You should set the password according to the file. So

    mysql -u root -p
    # Then type MySQL root password
    GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<password>';

Solution 3

PHPMYADMIN

  1. sudo apt-get purge phpmyadmin
  2. sudo apt-get autoremove
  3. sudo ap-get autoclean

MYSQL

  1. sudo systemctl stop mysql
  2. sudo apt-get remove mysql*
  3. sudo apt-get purge mysql

Solution 4

Remove MySQL

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

Remove MySQL folders

sudo rm -rf /etc/mysql /var/lib/mysql

Delete all MySQL files from File System

sudo find / -iname 'mysql*' -exec rm -rf {} \;

Remove PhpMyAdmin

sudo apt-get purge phpmyadmin

Cleanup system (dependences)

sudo apt-get autoremove
sudo apt-get autoclean
Share:
21,454

Related videos on Youtube

Gareth Jones
Author by

Gareth Jones

Updated on September 18, 2022

Comments

  • Gareth Jones
    Gareth Jones over 1 year

    I am sorry if this has been posted before. I have been learning the use of MySQL and phpMyAdmin. Having followed an installation guide during an instructional course, I installed the above applications. However, the root user and password for the association between them seems to be incorrect.

    I have tried removing and reinstalling, but this issue seems to follow on after the install as if there was a saved file or table containing old information regarding the previous install. Is there a way of fully removing both and all associated tables and files without having to resort to anything too drastic.

    Thanks.

  • Gareth Jones
    Gareth Jones over 5 years
    Many thanks all, that has sorted it. I have now re-installed and have it working correctly
  • ThunderBird
    ThunderBird over 5 years
    @GarethJones I'm glad your problem was resolved...