Step 1: Download the mysql installation package
Go to the official website of mysql to download the corresponding installation package. Since THE server I bought is centOS8, I was very upset at the beginning that there was no corresponding centOS option. Later I found the red Hat option.
Step 2: Upload the downloaded installation package to the cloud server. There are many methods. Due to the limitation of macOS, I chose the tool ‘File Zilla’. Connect to our server remotely through this tool.
Generally the default port is 22, you can also go to ali cloud console to check whether this port is open, in the ‘security group’ option
The following figure is shown after File Zilla is successfully connected:
Then just drag the downloaded installation package to the root directory of the server and wait for the upload to be successful.
Step 3: Decompress the uploaded installation package on the terminal
Mysql > create a folder in root directory mysql:
Run mkdir mysql
The mysql folder is created, and the next step is to unzip the installation package into the mysql folder
Run the tar -xvf mysql-8.0.28-1.el8.x86_64. RPM -bundle.tar -c mysql command
When unzipped, you can see many RPM files under the mysql file
The next step is to install mysql dependencies by executing commands in sequence
RPM -ivh mysql-community-common-8.0.28-1.el8.x86_64. RPM --nodeps --force RPM -ivh RPM --nodeps --force RPM -ivh mysql-community-client-8.0.28-1.el8.x86_64. RPM --nodeps --force RPM -ivh mysql-community-server-8.0.28-1.el8.x86_64. RPM --nodeps --force RPM -ivh mysql-community-server-8.0.28-1.el8.x86_64Copy the code
After each successful run, initialize the data and run the following command once
mysqld --initialize; \ chown mysql:mysql /var/lib/mysql -R; \ systemctl start mysqld.service; \ systemctl enable mysqld;Copy the code
Next, run the start database command below
Systemctl start mysqld // Start database systemctl stop mysqld // Stop database systemctl reload mysqld // Restart the databaseCopy the code
After the database is enabled, log in to the database
mysql -u root -p
Copy the code
You need to enter a password, and there will be a temporary password in the configuration file when you log in for the first time
cat /var/log/mysqld.log | grep password
Copy the code
After successful connection
SHOW VARIABLES LIKE ‘validate_password%’; You can see the validation plug-in for the database, if any, as shown below:
If it is empty, install plugin: install plugin validate_password soname ‘validate_password.so’; After installation, it will look like the picture above.
set validate_password_policy = 0; // Password verification level. 0 is the lowest level. Set VALIDATE_password_length = 4. // Set the password length according to your preferenceCopy the code
Then change the database password, if the password is changed to: root, the following command can be used
ALTER USER 'root' @ 'localhost' IDENTIFIED WITH mysql_native_password BY 'root';Copy the code
Step 4: Create a user to connect to the database remotely
CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Copy the code
Set all permissions of the user
GRANT ALL ON *.* TO 'root'@'%';
Copy the code
To open the remote connection database visualization tool on the local computer, I used Navicat
When creating a connection, fill in the public IP address and the corresponding password. It should be noted that if the connection fails, it indicates that the firewall of the cloud server caused the connection, and we can set it
I directly opened the database inbound port, the default database port 3306, so that the remote connection will be successful.