How I Recovered My Lost MySQL Databases After a MariaDB Installation (Without Timeshift Restore)
Losing databases unexpectedly can feel catastrophic — especially when it happens after installing something that’s supposed to help, not break things. That’s what happened when I installed MariaDB while setting up Daloradius on my Ubuntu system.
After installation, all my databases were gone, and phpMyAdmin started showing this dreaded message:
mysqli::real_connect(): (HY000/1698): Access denied for user 'phpmyadmin'@'localhost'
When I logged into the database, all my previous projects had vanished. But I eventually managed to recover everything manually — without using sudo timeshift --restore. Here’s how I did it step by step.
1. Understanding the Problem
When you install MariaDB on a system that already has MySQL, Ubuntu often treats MariaDB as a drop-in replacement for MySQL.
That means:
-
MySQL is automatically removed or replaced.
-
The folder
/var/lib/mysql(which contains all databases) is overwritten with a fresh MariaDB data directory. -
Your old database files are not deleted from disk immediately — but they’re moved, renamed, or left behind in a previous snapshot folder (if you use Timeshift or have manual backups).
As a result, logging into phpMyAdmin or MySQL shows no user-created databases.
2. Verifying That MariaDB Overwrote MySQL
To confirm that MySQL was replaced:
mysql --version
It returned something like
mysql Ver 15.1 Distrib 10.x.x-MariaDB, for Linux (x86_64)
That meant MySQL binaries were now replaced by MariaDB. Checking databases:
sudo mariadb -u root -p
SHOW DATABASES;
Only system databases like mysql, information_schema, and performance_schema appeared — everything else was gone.
3. Removing MariaDB Completely
To restore my system, I decided to remove MariaDB entirely.
sudo systemctl stop mariadb
sudo apt purge mariadb-server mariadb-client mariadb-common -y
sudo apt autoremove -y
sudo apt autoclean
Then, I verified that no MariaDB packages were still on the system:
dpkg -l | grep mariadb
If any showed up, I manually removed them too.
4. Reinstalling MySQL
Once MariaDB was gone, I reinstalled MySQL 8.0:
sudo apt update
sudo apt install mysql-server -y
There were a few configuration prompts and minor errors like:
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
I simply chose the default options (pressing Enter where prompted). After installation, MySQL was back, but with a fresh data directory — and, of course, no old databases.
5. Manually Restoring the Old Databases
Here’s where the manual recovery came in.
Step 1: Locate the old MySQL folder
I opened my Timeshift snapshots manually (without running restore).
Timeshift stores snapshots under:
/timeshift/snapshots/
Inside the latest snapshot folder, I navigated to:
/timeshift/snapshots/<snapshot-date>/localhost/var/lib/
Here, I found my old MySQL folder that contained all my previous .frm, .ibd, .ibdata1, and .myd database files.
Step 2: Stop the MySQL service
Before replacing anything, I stopped MySQL:
sudo systemctl stop mysql
Step 3: Backup the new (empty) MySQL folder
Just to be safe:
sudo mv /var/lib/mysql /var/lib/mysql_backup_new
Step 4: Copy the old MySQL folder from the snapshot
Then I copied my old databases back:
sudo cp -r /timeshift/snapshots/<snapshot-date>/localhost/var/lib/mysql /var/lib/mysql
(Replace <snapshot-date> with the correct snapshot folder name.)
Step 5: Set proper ownership and permissions
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 755 /var/lib/mysql
Step 6: Restart MySQL
sudo systemctl start mysql
If everything went fine, the MySQL service started normally.
6. Confirming the Recovery
Once MySQL was running again, I logged in:
sudo mysql -u root -p
Then checked all databases:
SHOW DATABASES;
To my relief, all my previous databases were back exactly as they were before the MariaDB installation.
phpMyAdmin also loaded perfectly again, without the “access denied” errors.
7. Backing Up Everything Immediately
The first thing I did after recovery was back up all databases to a single .sql file:
mysqldump -u root -p --all-databases > ~/backup_all_databases.sql
That way, even if something similar happens again, I can restore everything with one command:
mysql -u root -p < ~/backup_all_databases.sql
8. Key Takeaways
- MariaDB and MySQL share the same paths — installing one can silently replace the other.
- Your old data isn’t necessarily gone — it’s just no longer linked to the running service.
- Manual restoration works if you can access old system files via Timeshift or a backup.
- Always stop the MySQL service before overwriting /var/lib/mysql, and fix file permissions afterward.
- Keep regular SQL dumps to make recovery faster next time.
This experience was a reminder that even routine installations can wipe out critical data if we’re not careful.
By manually restoring the /var/lib/mysql directory from a snapshot and resetting file permissions, I managed to recover every single database without using full system restore tools.
So, if you ever find yourself staring at an empty phpMyAdmin after a MariaDB install — don’t panic.
Your data is probably still there. You just need to bring it home.
