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 tutorial describes how you can deploy MySQL in Huawei Cloud EulerOS (HCE) 2.0.
Preparations
- Prepare an ECS and assign a public IP address or elastic IP address (EIP) to the ECS.
- Ensure that inbound security group rules allow traffic to flow to the ECS over ports 22 and 3306.
Procedure
- Install the MySQL server and client.
- Run the following command to install the MySQL server and client:
dnf install mysql-server mysql-common mysql -y
- Run the following command to check the MySQL version:
mysql -V
If information similar to the following is displayed, the MySQL server and client are successfully installed:
mysql Ver 8.0.37 for Linux on x86_64 (Source distribution)
- Run the following command to install the MySQL server and client:
- Configure MySQL.
- Run the following command to start MySQL:
systemctl start mysqld
- Run the following command to 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
- Run the following command to perform security configuration for MySQL:
mysql_secure_installation
Customize options based on personal requirements and prompt information.
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 setup 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!
- Run the following command to start MySQL:
- Remote connect to the database.
- Run the following command on the MySQL server to connect to the database:
mysql -uroot -p
Enter the password of the root user.
- Enter the following statement to create a test account and password:
create user 'test'@'%' identified by 'test****';
test indicates the account name, and test**** indicates the password.
- Execute the following statement to grant all database permissions to the test account:
grant all privileges on *.* to 'test'@'%';
- Execute the following statement to update the permissions:
flush privileges;
- Execute the following command to exit the database:
exit
- Run the following command on the MySQL client to remotely connect to the database:
mysql -h <IP address of the MySQL client> -utest -p
Alternatively, use the Navicat or Visual Studio Code plug-in for remote connections.
- Run the following command on the MySQL server to connect to the database:
The password and permission configurations are used only for tests. Exercise caution when using them in the service environment.
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