MySQL Tutorial

MySQL Installation and Configuration

MySQL Database Operations

Database Design

MySQL Data Types

MySQL Storage Engines

MySQL Basic Operations of Tables

MySQL Constraints

MySQL Operators

MySQL Function

MySQL Manipulate Table Data

MySQL View

MySQL Indexes

MySQL Stored Procedure

MySQL Trigger

MySQL Transactions

MySQL Character Set

MySQL User Management

MySQL Database Backup and Recovery

MySQL Log

MySQL Performance Optimization

Uninstall MySQL in Linux CentOS (Preparation Before Installing MySQL in Linux)

Before installing MySQL on a Linux operating system, check to see if an older version of MySQL is installed on your current system. If there is, it is best to uninstall the old version of MySQL first, otherwise there may be conflicts.

The steps for uninstalling the old version of MySQL are as follows: 

1) Use the following command to check whether MySQL is installed in the current system. The command and running results are as follows:
[root@bogon Desktop]# rpm -qa|grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64
The result shows that the MySQL installed on Linux is the mysql-libs-5.1.71-1.el6.x86_64 version.

The following 2 points should be noted:
  • Starting from MySQL 5.0, the service name of MySQL has been changed to mysql instead of mysqld of 4.*.
  • Under CentOS 7, the default installed database is MariaDB. Before installing MySQL, you need to uninstall the MariaDB database.

2) Stop the MySQL service, uninstall mysql-libs-5.1.71-1.el6.x86_64, the command is as follows:
service mysql stop
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
Note: If you get an error, you can use the command rpm -ev mysql-libs-5.1.71-1.el6.x86_64 --nodeps or rpm -e --noscripts mysql-libs-5.1.71-1.el6.x86_64 to uninstall MySQL .

3) Find the directory of the previous version of MySQL, and delete the files and libraries of the old version.
find / -name mysql
After the MySQL directory is displayed, the directory can be deleted using the following command.
rm -rf 目录名
4) Find out again whether MySQL is installed in the current system.
rpm -qa|grep -i mysql
If no result is displayed, it means that it has been uninstalled cleanly, and then you can directly install MySQL. 
  1. Uninstall MySQL in CentOS:

    • Description: Uninstall MySQL package from CentOS using the package manager.
    • Command:
      sudo yum remove mysql-server mysql
      
  2. Remove MySQL from CentOS system:

    • Description: Remove MySQL server and client packages from the CentOS system.
    • Command:
      sudo yum remove mysql-server mysql
      
  3. Cleanly uninstall MySQL on Linux:

    • Description: Cleanly uninstall MySQL, removing configuration files and dependencies.
    • Commands:
      sudo yum remove mysql-server mysql
      sudo rm -rf /var/lib/mysql
      sudo rm -rf /etc/my.cnf
      
  4. Preparing for MySQL reinstall on CentOS:

    • Description: Remove existing MySQL packages and prepare for a fresh installation.
    • Commands:
      sudo yum remove mysql-server mysql
      sudo yum clean all
      
  5. Backup MySQL databases before uninstall:

    • Description: Before uninstalling MySQL, it's crucial to back up your databases to avoid data loss.
    • Command (for individual databases):
      mysqldump -u [username] -p[password] [database_name] > backup.sql
      
  6. Uninstall MySQL and dependencies CentOS:

    • Description: Uninstall MySQL and its dependencies from CentOS.
    • Command:
      sudo yum autoremove mysql-server mysql
      
  7. Purge MySQL from CentOS:

    • Description: Purge MySQL packages and configuration files from CentOS.
    • Command:
      sudo yum erase mysql-server mysql
      
  8. Completely remove MySQL on Linux:

    • Description: Completely remove MySQL, including packages, configuration files, and data directories.
    • Commands:
      sudo yum erase mysql-server mysql
      sudo rm -rf /var/lib/mysql
      sudo rm -rf /etc/my.cnf
      
  9. CentOS uninstall MySQL and reinstall steps:

    • Description: Steps to uninstall MySQL on CentOS and prepare for a fresh installation.
    • Commands:
      sudo yum remove mysql-server mysql
      sudo yum clean all
      
  10. Check for existing MySQL installations CentOS:

    • Description: Verify if MySQL is already installed on CentOS.
    • Command:
      rpm -qa | grep mysql