Home > Database > Mysql Tutorial > How to reinstall MySQL in Linux system

How to reinstall MySQL in Linux system

PHPz
Release: 2023-04-20 11:28:19
Original
1674 people have browsed it

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
Copy after login

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
Copy after login
  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
Copy after login
  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
Copy after login

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

sudo yum install mysql-server
Copy after login
  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
Copy after login

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

sudo mysql_install_db
Copy after login

Then use the following command to start the MySQL service:

sudo systemctl start mysql
Copy after login
  1. Verify installation

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

sudo mysql -uroot -p
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template