How to Completely Remove and Clean Up MySQL Packages on CentOS for Fresh Installation


2 views

When dealing with package management in CentOS, sometimes MySQL leaves residual components even after attempted removal. The key error message "package is available but not marked for installation" typically indicates leftover dependencies or conflicting packages.

First, let's check all installed MySQL-related packages:

rpm -qa | grep -i mysql

Based on your output showing mysql55-libs, libmysqlclient15, and php-mysql, we'll need to remove these specifically:


yum remove mysql55-libs-5.5.10-1.w5
yum remove libmysqlclient15-5.0.77-1.1.w5 
yum remove php-mysql-5.3.8-1.1.w5

After package removal, manually delete remaining files:


rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
rm -rf /usr/my.cnf
find / -name "*mysql*" -exec rm -rf {} \;

For particularly stubborn cases, use rpm directly:


rpm -e --nodeps mysql55-libs-5.5.10-1.w5
rpm -e --nodeps libmysqlclient15-5.0.77-1.1.w5

Yes, you can perform some cleanup via SFTP by:

  1. Connecting to your server with SFTP client
  2. Navigating to /var/lib/mysql and deleting contents
  3. Removing configuration files in /etc/

Before fresh MySQL installation:


yum clean all
yum update

Confirm complete removal by running:


mysql --version
which mysql

Both commands should return no output if MySQL is properly removed.

Now you can safely install MySQL:


yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld

When dealing with stubborn MySQL residues on CentOS, I've found the situation often requires more than just yum remove. Here's how I typically handle this:

# First, list all MySQL-related packages
rpm -qa | grep -i mysql

# Expected output similar to:
mysql55-libs-5.5.10-1.w5
libmysqlclientl5-5.0.77-1.1.w5
php-mysql-5.3.8-1.1.w5

When yum fails, I resort to direct rpm commands. This is my step-by-step approach:

# Remove each package individually
rpm -e --nodeps mysql55-libs-5.5.10-1.w5
rpm -e --nodeps libmysqlclientl5-5.0.77-1.1.w5
rpm -e --nodeps php-mysql-5.3.8-1.1.w5

# Verify removal
rpm -qa | grep -i mysql

Even after package removal, I always check for leftover files:

# Find all MySQL-related files
find / -name "*mysql*" 2>/dev/null

# Common directories to clean:
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
rm -f /etc/my.cnf
rm -rf /usr/share/mysql

For systems with complex dependencies like PHP-MySQL, I use this sequence:

# First remove dependent packages
yum remove php-mysql

# Then proceed with MySQL removal
yum remove mysql mysql-server mysql-libs

Regarding SFTP access - while you can delete files via SFTP, I strongly recommend using terminal commands for complete cleanup:

# SFTP equivalent would require:
sftp> rm /path/to/mysql/file
sftp> rmdir /path/to/mysql/directory

But manual file deletion might leave package database inconsistencies.

Before fresh installation, I always run:

# Clean yum cache
yum clean all

# Rebuild rpm database (caution!)
rm -f /var/lib/rpm/__db*
rpm --rebuilddb

# Verify no conflicts remain
yum list installed | grep -i mysql