How to uninstall and reinstall MySQL

General steps to uninstall and reinstall MySQL on a Linux system:

1. Uninstall MySQL:

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
```

上述命令将卸载MySQL服务器、客户端和常用文件,并清理相关的依赖项和配置文件。

2. Delete the MySQL database directory:

sudo rm -rf /var/lib/mysql

This command will delete the MySQL database directory, which contains the database files and logs of the MySQL server.

3. Install MySQL:

sudo apt-get install mysql-server

This command will install MySQL server from the Ubuntu software repositories.

4. Run the MySQL security installation script:

sudo mysql_secure_installation

5. Start the MySQL server:

This command will start the MySQL service.

sudo systemctl start mysql

You can check if the MySQL service is running with the following command:

sudo systemctl status mysql

If the MySQL service is running, the output should show the service status as "active (running)".

The MySQL server is now ready to use. If you run into any issues, you can check the MySQL log files for more information.

 

Note: The above steps may be different for different Linux distributions. Always back up server data and configuration files before performing important operations.

Guess you like

Origin blog.csdn.net/Toml_/article/details/131952417