Mysql – completely remove mariadb database and root password

mariadbMySQL

The system is Fedora 32. Mariadb was installed and operational; it is now necessary to reinitialize Mariadb and all data and users.

I removed mariadb-server and mariadb and erased /etc/my.cnf and my.cnf.d. I then reinstalled mariadb and mariadb-server and ran the mysql_secure_installation script. It found the original root password but otherwise completed normally.

I then logged into mariadb. I expected to find the users from the original installation had been removed; however they had not.

show databases; shows the original tables. They were not removed.

select * from mysql.user; showed the original users.

How can mariadb be completely removed including all users, data, and passwords?

Best Answer

You need to delete the data in your datadir, since that is where this is stored. The default location is /var/lib/mysql/. Shut down MariaDB and delete everything inside the datadir without deleting the datadir itself (as you want to avoid having to recreate the directory with exactly the right permissions):

sudo systemctl stop mariadb
sudo rm -rf /var/lib/mysql/*

Then use mysql_install_db to re-initialise the datadir.