Skip to main content

Uninstall MySQL

Updated Oct 20, 2019 ·

Uninstall

  1. Remove the installed MySQL packages, including the server and client packages:

    sudo apt-get purge -y mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
  2. To remove any leftover dependencies that are no longer needed after removing MySQL:

    sudo apt-get autoremove -y
  3. Clear any cached packages that are stored on your system to free up space:

    sudo apt-get clean
  4. To completely remove MySQL's configuration and data files, which are not removed by the above commands, delete the following directories manually:

    sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql /var/log/mysql.* /var/run/mysqld
  5. If there are still MySQL packages on your system, you can list them and remove any remaining MySQL packages:

    dpkg -l | grep mysql

    If you find any packages, remove them manually using:

    sudo dpkg --purge <package-name>

    Sample:

    sudo apt-get purge --auto-remove -y mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core mysql-community-server-debug mysql-community-test mysql-community-test-debug

    Check again:

    dpkg -l | grep mysql
  6. If you get an error deleting mysql-common, inspect and edit the Post-Removal Script:

    sudo vi /var/lib/dpkg/info/mysql-common.postrm

    Run the purge command again:

    sudo dpkg --purge mysql-common