Install MySQL 8.0 on Huawei Cloud EulerOS

Install MySQL 8.0 on EulerOS

insert image description here

Install MySQL

MySQL is a common and powerful database management system of choice when creating a EulerOS-based server. In this blog, I will show you how to install MySQL 8.0 on EulerOS.

Step 1: Update the system

Before we start, let's make sure the system is updated to the latest version. Open a terminal and execute the following command:

sudo yum update

Enter a password to confirm.
insert image description here

Step 2: Add the MySQL Yum repository

MySQL provides a Yum repository that allows us to install and update MySQL packages conveniently. Execute the following command in the terminal:

sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

This command will download and install the RPM package from the MySQL Yum repository.

Step 3: Install MySQL 8.0

Next, we can use the following commands to install the MySQL 8.0 server and client packages:

sudo yum install mysql-community-server

After executing the command, the installed list of packages will be displayed. Press ythe key and press Enter to continue the installation. ,
insert image description here

Step 4: Start the MySQL service

After the installation is complete, we can use the following command to start the MySQL service:

sudo systemctl start mysqld

After executing this command, the MySQL server will start.
insert image description here

Step 5: (Optional) Configure the MySQL service to start automatically at startup To
configure the server to automatically start the mysql service:

sudo systemctl enable mysqld

Step 6: Configure MySQL Security

After starting the MySQL service, we need to do some configuration to improve security and set the root user's password. Run the following command:

sudo mysql_secure_installation

This command will prompt you to set a password for the root user, delete anonymous users, disable remote login for the root user, delete the test database, etc. Follow the prompts to complete the configuration.

Step 7: Verify MySQL Installation

Now, we can verify that MySQL was installed successfully. Run the following command:

sudo systemctl status mysqld

insert image description here
You will see in the output if MySQL is running active (running).

Also, you can check the MySQL version with the following command:

mysql --version

insert image description here
If you can see the MySQL version information, then the installation was successful.

Congratulations, you have successfully installed MySQL 8.0 on EulerOS!

configuration file

  1. Find the MySQL configuration file my.cnf. On EulerOS systems, it is usually located at /etc/my.cnf or /etc/mysql/my.cnf. You can find out with the following command:
find /etc -name my.cnf
  1. Open the my.cnf file with a text editor such as vi or nano:
vi /etc/my.cnf
  1. In the my.cnf file [mysqld], you can make various configuration changes as needed. Here are some commonly used configuration options:
    insert image description here
  • Modify the listening address and port of MySQL:
bind-address = 0.0.0.0
port = 3306
  • Set the character set of MySQL:
character-set-server = utf8mb4 
collation-server = utf8mb4_unicode_ci
  • Configure the maximum number of concurrent MySQL connections:
max_connections = 1000
  • Adjust the related settings of MySQL log:
log_error = /var/log/mysql/error.log 
general_log = 1 
general_log_file = /var/log/mysql/general.log
  • Configure the cache size of MySQL:
key_buffer_size = 256M 
innodb_buffer_pool_size = 1G

Note: The above is just an example configuration, and the specific configuration can be adjusted according to your needs and system resources.

  1. After making configuration changes, save and close the file.

  2. Restart the MySQL service for the configuration changes to take effect:

sudo systemctl restart mysqld

From then on, you have successfully configured the configuration file for MySQL. Note that MySQL has a wide variety of configuration options, and different configuration options have different effects, so it is recommended to back up the original configuration file before modifying the configuration file, and be careful to make appropriate configuration changes.

Guess you like

Origin blog.csdn.net/weixin_45626288/article/details/131550860