Install MySQL on Centos7
We first need to install a Centos7 VMware in the virtual machine to install Centos7
MySQL installation
1. Download the wget command
yum -y install wget
2. Download the mysql installation package online
wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
3. Install MySQL
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
4. Install mysql service
First enter the cd /etc/yum.repos.d/ directory
cd /etc/yum.repos.d/
Install the MySQL service (this process may be a bit slow)
yum -y install mysql-server
If you encounter the following error situation
Please execute the following command
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
Then execute the following command again
yum -y install mysql-server
5. Start MySQL
systemctl start mysqld
查看进程:
ps -ef | grep mysql
Modify MySQL temporary password
After MySQL is successfully installed, there will be a temporary password. We can use the grep command to view the temporary password. First log in to MySQL, and then change the MySQL password.
1. Obtain MySQL temporary password
grep 'temporary password' /var/log/mysqld.log
2. Use the temporary password to log in first
mysql -uroot -p
My temporary password is: jlHfYlWae0:>
3. Change the password verification strength of MySQL to low risk
set global validate_password_policy=LOW;
4. Modify the password length of MySQL
set global validate_password_length=5;
5. Change the MySQL password to admin
ALTER USER 'root'@'localhost' IDENTIFIED BY 'admin';
Allow remote access
1. First, turn off the Cenots firewall.
sudo systemctl disable firewalld
2. Modify MySQL to allow anyone to connect
1) First log in to MySQL
mysql -uroot -padmin
2) Switch to mysql data
use mysql;
3) View the user table
select Host,User from user;
It was found that the root user is only allowed to log in to the localhost host.
4) Modify to allow access from any address
update user set Host='%' where User='root';
5) Refresh permissions
flush privileges;