CentOS7 installs MariaDB by default, you need to add MySQL official yum source to install mysql5.7
1. Download the official yum source
First you need to download the official yum source
wget https://repo.mysql.com/mysql57-community-release-el7.rpm
2. Install yum source
yum -y install mysql57-community-release-el7.rpm
3. Install mysql server
Everything is ready, now you can install the mysql server
yum -y install mysql-community-server
4. Start the service
Now use systemctl to start the mysql daemon
systemctl start mysqld
Starting mysql for the first time will initialize the database, so it takes some time
5. View root password
When the database is initialized, a default password is set for root, which can be found in the log file
less /var/log/mysqld.log # 查看日志查看密码
# 会有一行 password is generated XXXXX
Or you can use the following statement to extract the password directly
grep "password is generated" /var/log/mysqld.log | awk '{print $NF}'
After finding the password, you can use the following command to enter the password to enter the database
mysql -uroot -p
The first time you enter the database, you can only change the password, not do anything
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
The new password here cannot be too simple, because MySQL has complexity requirements for passwords by default
The complexity requirement can be turned off by the following command
mysql> set global validate_password_policy=0; # 关闭密码复杂性策略
mysql> set global validate_password_length=4; # 设置密码最低长度为4