Install MySQL 8.0 on EulerOS
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.
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 y
the key and press Enter to continue the installation. ,
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.
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
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
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
- 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
- Open the my.cnf file with a text editor such as vi or nano:
vi /etc/my.cnf
- In the my.cnf file
[mysqld]
, you can make various configuration changes as needed. Here are some commonly used configuration options:
- 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.
-
After making configuration changes, save and close the file.
-
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.