I have PHP and Mysql was already running on Ubuntu VERSION 20.04

Today, I have tried to install the Maria db, but it wasn't working, So i have removed the mariadb using below command

apt-get purge mariadb-server mariadb-*

Now mysql is not working anymore, when i ran

sudo service mysql status

It gives me error,

Unit mysql.service could not be found.

I have tried following things but none of them work, it is giving same error.

sudo service mysql stop
sudo systemctl stop mysqld
sudo systemctl stop mysql

1 Answer 1


This seems to be a common issue when people uninstall MariaDB. Generally the best option is to wipe MySQL completely, then reinstall it. Here are the steps:

sudo apt remove --purge mysql*
sudo apt purge mysql*
sudo apt autoremove
sudo apt autoclean
sudo apt remove dbconfig-mysql

It would probably also be a good idea to ensure the data directory is gone.

  1. check if /var/lib/mysql exists, if so, do (2)
  2. sudo rm -Rf /var/lib/mysql

From there you can re-install MySQL:

  1. sudo apt install mysql-server
  2. sudo mysql_secure_installation
  3. (optional) restore databases & user accounts

Hope this helps you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .