Home  >  Article  >  Database  >  How to reinstall MySQL in Linux system

How to reinstall MySQL in Linux system

PHPz
PHPzOriginal
2023-04-20 10:12:021663browse

Reinstalling MySQL is one of the common tasks of server management. Different systems and distributions may have different methods, but the general steps are basically the same. In this article, you will be introduced to how to reinstall MySQL in a Linux system.

  1. Uninstall the old version of MySQL

You must uninstall the old version before reinstalling MySQL. If you are using Ubuntu or Debian system, please use the following command:

sudo apt-get remove mysql-server
sudo apt-get autoremove
sudo apt-get autoclean

If you are using Red Hat, Fedora, CentOS and other systems, execute the following command in the terminal:

sudo yum remove mysql-server
sudo yum autoremove
sudo yum clean all
  1. Delete the old version of MySQL data directory

After uninstalling MySQL, you need to delete the old version of the data directory. This directory is usually located at /var/lib/mysql during the installation process. Use the following command to delete it:

sudo rm -rf /var/lib/mysql
  1. Install a new version of MySQL

Next, you can start the installation New version of MySQL. Use the following command to install on Ubuntu and Debian systems:

sudo apt-get update
sudo apt-get install mysql-server

To install MySQL on Red Hat, Fedora and CentOS systems, please execute the following command in the terminal:

sudo yum install mysql-server
  1. Configure MySQL

After installing MySQL, some basic configuration is required. On Ubuntu and Debian systems, you can use the following command:

sudo mysql_secure_installation

On Red Hat, Fedora, and CentOS systems, you need to use the following command:

sudo mysql_install_db

Then use the following command to start the MySQL service:

sudo systemctl start mysql
  1. Verify installation

After the installation is completed, you can use the following command to verify whether it is successful:

sudo mysql -uroot -p

Then enter the MySQL administrator password to enter MySQL shell. If you log in successfully, the installation is complete.

In this article, we introduce the basic steps to reinstall MySQL in a Linux system. Knowing these steps, you can easily install and configure MySQL and ensure that MySQL is functioning properly on your server.

The above is the detailed content of How to reinstall MySQL in Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn