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.
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
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
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
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
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!