Deploying MySQL
Introduction
MySQL is an open-source relational database management system. Like other relational databases, MySQL stores data in tables consisting of rows and columns. Users can define, manipulate, control, and query data using a structured query language (usually called SQL). This section describes how to deploy MySQL in Huawei Cloud EulerOS 2.0 (HCE 2.0).
Preparations
- Prepare two ECSs and assign a public IP address or an EIP to each of them.
- Ensure that inbound security group rules allow traffic to flow to the ECS over ports 22 and 3306.
Prerequisites
A yum repository has been configured. For details about how to configure a yum repository accessed over the Internet, see Configuring Repositories and Installing Software for HCE.
Procedure
- Install the MySQL server and client.
- Install the MySQL server and client.
dnf install mysql-server mysql-common mysql
- Check the MySQL version.
mysql -V
If information similar to the following is displayed, the installation is successful:
mysql Ver 8.0.37 for Linux on x86_64 (Source distribution)
- Install the MySQL server and client.
- Configure MySQL.
- Start the MySQL service.
systemctl start mysqld
- Check the MySQL status.
systemctl status mysqld
If active (running) is displayed, MySQL is started.
To set mysqld to automatically enable upon system boot, run the following command:
systemctl enable mysqld
- Perform security configuration for MySQL.
mysql_secure_installation
Customize options as needed.
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to set up VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y // Choose whether to set the password component. There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 // Select the password security policy. Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log in to MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y // Choose whether to remove anonymous users. Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y // Choose whether to disallow remote login of the root user. Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y // Choose whether to remove the test database. - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y // Choose whether to reload privilege tables. Success. All done!
- Start the MySQL service.
- Remotely connect to the database.
- Connect to the database.
mysql -uroot -p
Enter the password of the root user.
- Create a test account and password.
create user 'test'@'%' identified by 'xxxxxx';
xxxxxx is the password.
- Grant all database permissions to the test account.
grant all privileges on *.* to 'test'@'%';
- Update the permissions.
flush privileges;
- Exit the database.
exit
- Install the MySQL client on another ECS.
dnf install mysql-common mysql
- Connect to the database from the client.
mysql -h <MySQL server IP> -utest -p
Alternatively, use the Navicat or Visual Studio Code plug-in for remote connections.
- Connect to the database.

If the database connection failed, check whether the firewall is disabled or whether the MySQL port is enabled. The default port is 3306. The password and permission settings are used for tests only. Do not use them in a service environment unless absolutely necessary.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot