Install mysql on the server
One, MySQL
1.0 Preparation
Installation package address: https://downloads.mysql.com/archives/community/
Enter directly through the address, you can directly see the last picture in preparation; it is required to enter from the mysql official website homepage
1.1 Install mysql
1. Upload the mysql-community-5.7-Linux-rpm.zip file to the directory under Linux
. rz
If it is not installed, you can use the commandsudo yum install lrzsz
2. Decompress the compressed package
tar -xvf mysql-package.tar.gz
3. Create the MySQL data directory: Execute the following command to create the data directory used to store the MySQL database:mkdir /root/tools/tomcat
4. Start MySQL: systemctl start mysqld
After successful startup, execute ps -ef|grep mysql
the command to check whether the process exists
5. Run the MySQL security script to strengthen security and set the root password: sudo mysql_secure_installation
After running, press Enter directly and you will be prompted to set the root password. After entering the password twice, the reset is successful.
6. Log in to MySQL:
mysql -u root -p
7. Exit MySQLexit
Command: turn on/off mysql
sudo systemctl start mysql
sudo systemctl stop mysql
1.2 Uninstall mysql
Steps:
1. Open the terminal and log in to the server with root privileges.
2. Stop the MySQL service. Depending on your Linux distribution and version, run the appropriate command from the following:
-
For Ubuntu or Debian systems, you can run the following command:
sudo systemctl stop mysql
-
For CentOS, Fedora or RHEL systems, you can run one of the following commands:
sudo systemctl stop mysqld
Orsudo service mysqld stop
3. Use the package manager for your Linux distribution to uninstall MySQL. Here are a few common examples: -
For Ubuntu or Debian systems, you can run the following command:
sudo apt-get purge mysql-server mysql-client mysql-common
-
For CentOS, Fedora or RHEL systems, you can run the following command:
sudo yum remove mysql-server mysql-client
4. The uninstallation process may also involve deleting MySQL-related data and configuration files. You can choose to delete or keep these files. If you plan to reinstall MySQL, it is recommended to delete these files.
5. After completing the uninstallation, you can run the following command to confirm whether MySQL has been successfully uninstalled: mysql --version
If MySQL has been uninstalled correctly, the terminal will display an error message similar to "Command not found".
NOTE: Please proceed with caution to ensure you do not lose important databases and data. Before uninstalling MySQL, it is best to back up the database and related files.