Excellent software and practical tutorials
A graphic introduction toCentos7.X is used belowYUMCommand to install MySQL 8.0. During the installation process, I encountered various pitfalls. I summarized and optimized the installation steps and some error solutions.
mysqlOfficial download address:https://dev.mysql.com/downloads/mysql/
First, download the rpm package of mysql8.0. Log in to the server and enter the download link as the root user.
wget -i -c http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
The downloaded rpm file package is in the root user's directory. Enter the ls command to view the files in the current directory.
We can see that mysql80-community-release-el7-1.noarch.rpm has been downloaded to the server.
Install yum and execute the command
yum -y install mysql80-community-release-el7-1.noarch.rpm
During the installation process, you may encounter errors caused by MySQL version conflicts, which can be solved by running rpm -e confictcompoent -- nodeps. The following example illustrates this:
For example, the conflicting package is mysql-5.0.77-4.el5_6.6.x86_64
rpm -e mysql-5.0.77-4.el5_6.6.x86_64 --nodeps
Delete the conflicting MySQL version and you can install it normally using the command.
Execute the installation command to install mysql
yum -y install mysql-community-server
(1/6): mysql-community-common-8.0.19-1.el7.x86_64.rpm | 605 kB 00:00:00
(2/6): mysql-community-libs-8.0.19-1.el7.x86_64.rpm | 4.0 MB 00:00:00
(3/6): mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm | 1.3 MB 00:00:00
(4/6): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
(5/6): mysql-community-client-8.0.19-1.el7.x86_64.rpm | 41 MB 00:00:00
(6/6): mysql-community-server-8.0.19-1.el7.x86_64.rpm | 436 MB 00:00:00
During the installation process, you need to download the installation package. The speed depends on the network speed of your personal server. Wait patiently for a while and then "complete!" appears, indicating that the installation is complete.
Enter the command to view the installed version information
rpm -qi mysql-community-server
MySQL has been installed successfully, the name is mysql-community-server, and the version is 8.0.19.x86_64 bit.
Execute the command to start mysql
systemctl start mysqld.service
Use the systemctl status mysqld command to check the status of mysql.
systemctl status mysqld
Set up MySQL at startup
systemctl enable mysqld.service
At this point, mysql8.0 has been installed successfully. Now let's start configuring the newly installed MySQL8.0
First set and modify the mysql connection password:
grep 'temporary password' /var/log/mysqld.log
Get the temporary password of mysql8.0
root@localhost: The following is the temporary password. Copy and save it in a notepad for future use.
Enter the command to log in to mysql
mysql -u root -p
Here you are prompted to enter the login password. Copy the password in Notepad, then paste it after Enter password: press ctrl+v and press Enter to enter mysql.
Now you have successfully logged into mysql.
The next thing you need to do is to change the password of mysql8.0. Enter the following after mysql>:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Change to the password you want to set';
Regarding password setting, MySQL has strengthened the password setting strength, requiring it to contain uppercase letters, lowercase letters, special characters and be greater than 8 characters. If the setting is simple, it will prompt that the modification failed. Please pay attention here!
After changing the password, the command prompt "Query OK, 0 rows affected (0.00 sec)" indicates that the password has been changed successfully. Enter the quit command to exit the MySQL interface.
At this point, the installation of MySQL has been completed. Don't think that you can use MySQL 8.0 with confidence after the installation is complete. This is just the beginning. After the installation, you still need to configure MySQL.
vi /etc/my.cnf
Remove the # number in front of innodb_buffer_pool_size and change the value to 1024M. In theory, the value of this item is 70% of system memory. Anything exceeding this value will be stored in swap and read. If swap space is not set, mysql will not be able to start.
innodb_buffer_pool_size = 1024M
Copy and paste the following content at the bottom of my.cnf
sort_buffer_size = 2M join_buffer_size = 250K read_buffer_size = 2M read_rnd_buffer_size = 250K key_buffer_size = 32M max_allowed_packet = 32M symbolic-links=0 character-set-server = utf8mb4 collation-server = utf8mb4_general_ci init_connect='SET NAMES utf8mb4' max_connections = 800 max_connect_errors = 1000 max_allowed_packet = 1024M interactive_timeout = 1800 wait_timeout = 1800 tmp_table_size = 64M max_heap_table_size = 256M query_cache_size = 64M thread_stack = 256K
After completing the above configuration, the installation of mysql has come to an end. Now use phpMyAdmin to manage sql!
mysql control commands:
systemctl start mysqld
systemctl stop mysqld stop mysqld
systemctl restart mysqld
systemctl enable mysqld Set to start at boot
systemctl status mysqld View MySQL Server status
Here are some common commands for mysql:
View startup item configuration
vi /lib/systemd/system/mysqld.service
Log in to mysql and enter the set mysql password
mysql -hlocalhost -uroot -p
If MYSQL is unable to exit, enter two commands in succession to exit
'/c exit;
Solution for code=exited, status=1/FAILURE:
If the operating system does not allocate swap space, MYSQL will fail after running for a period of time.
Use the command free -m to check the memory configuration. If the number after Swap is 0, you need to add swap.
Create a file with preallocated space of the specified size:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=8388608
Create an 8G swap space for data exchange when memory is insufficient. Use the ls command to check the size of the file just created.
ls -lh /swapfile
Change the permissions of the swap file:
sudo chmod 600 /swapfile
Format the swap file:
sudo mkswap /swapfile
Enable the swap file:
sudo swapon /swapfile
Modify the fstab file to enable swap to take effect automatically after reboot (or directly use the command echo '/swapfile swap swap sw 0 0' | sudo tee -a /etc/fstab to set the swap file to start at boot)
sudo vi /etc/fstab
Add at the end of the file
/swapfile swap swap sw 0 0
If you want to stop swapping
Stop swap
swapoff /swapfile
Delete swap files
rm -ir /swapfile
Finally, execute free -m to check the value after Swap. If it is 0, the deletion is successful.
The installation of mysql8.0 using yum is complete. If you have any questions, you can discuss in the comment section below.