0 Preface
Yesterday I planned to install MySql8.0 on CentOs7. I thought it was a very simple thing, but I did not expect to step on a lot of pits. I hereby record it. Most of the installation tutorials on the Internet are for 5.7 and previous versions, or are more cumbersome, I hope this blog can help you.
1 Add yum source
mysql seems to be removed from the yum source, first add it manually and create a new file:
vi /etc/yum.repos.d/mysql-community.repo
After creating this file, add the following content:
mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
If you encounter problems with gpgkey in the subsequent steps, change the penultimate line to gpgcheck=0.
2 Installation
First update MySQL by running the following command to update the yum source:
yum update
When prompted, press y to
update and enter the following command to install:
yum install mysql-community-server
Wait a moment for the installation to end
3 Modify password
You need to further modify the password after installation.
First, start the MySql server:
service mysqld start
Next, we log in with the root account. MySql has an initialized root account. First, we use the following command to obtain the password:
grep 'temporary password' /var/log/mysqld.log
The place where the arrow points is your password, copy it.
Then formally log in:
mysql -uroot -p
After entering the above command, enter the password you just copied to log in successfully, and then modify the initial password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你要改的密码';
Here is the last place to step on the pit, that is, if your password is not strong enough, you will not be able to modify it successfully. At this time, you can reduce the password strength requirement. 0 is the lowest level requirement. At this time, you can set a pure alphanumeric password and execute it again. One-step command:
set global validate_password.policy=0;