Completely removes MySQL packages, data directories, and configuration files from your system after optional backup.
Developers often remove MySQL to reclaim disk space, switch to PostgreSQL, or resolve port conflicts during local testing.
Create a full dump of critical schemas such as ecommerce
to preserve tables like Customers
, Orders
, and Products
.
Run mysqldump -u root -p ecommerce > ecommerce_backup.sql
.This file keeps the whole structure and data, ensuring OrderItems
remain linked to Orders
.
Use sudo apt-get remove --purge mysql-server mysql-client mysql-common
. The --purge
flag deletes configuration files, preventing orphaned configs.
Execute sudo rm -rf /var/lib/mysql /etc/mysql
to erase data files and configs.Verify with sudo find / -name "*mysql*"
.
Run sudo yum remove mysql mysql-server
, followed by sudo rm -rf /var/lib/mysql
. Clean cached metadata with sudo yum clean all
.
Type mysql --version
.A “command not found” message means the uninstallation succeeded.
Restore your ecommerce backup into PostgreSQL using tools like pgloader
to migrate Customers
and related tables.
Leaving backups on the same disk: Store ecommerce_backup.sql
off-machine to avoid accidental loss during disk cleanup.
Skipping the --purge flag: Without it, config files remain and can block future PostgreSQL ports.
If mysql
still starts, check systemd with sudo systemctl status mysql
and disable lingering services via sudo systemctl disable --now mysql
.
.
Only if you remove /var/lib/mysql
. Back up first, then delete to reclaim space.
Yes. Re-install with apt-get install mysql-server
or yum install mysql-server
, then restore ecommerce_backup.sql
.
Use pgloader ecommerce_backup.sql postgres://user@localhost/ecommerce
to convert schema and data.