- I like that all operations are under root authority. If you are prompted to have no authority, please add
sudo
or switch to aroot
user. - The main reference blog for the entire installation process: CentOS 7-Install MySQL 5.7
1. Installation preparation
- First, check whether your version is centos 7
cat /etc/redhat_release
- Check if mysql already exists in your system
rpm -qa | grep -i mysql
- I have already installed it, so I found out that it really exists.
- Uninstall the installed mysql, refer to the blog: Completely uninstall mysql under centos
yum remove mysql1 mysql2 # mysqlx 指具体的mysql软件,如mysql-community-client-5.7.31-1.el7.x86_64
rm -rf /var/lib/mysql
rm -rf /etc/my.cnf
- Add mysql installation source
rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
- Check whether the installation source is added successfully, the following content indicates that the addition is successful.
yum repolist all | grep mysql | grep enabled
2. Install mysql
- Install the latest mysql, there will be a corresponding prompt message after installation
yum -y install mysql-community-server
- Start mysql and turn on self-start after boot.
systemctl start mysqld # 开启mysql服务
systemctl enable mysqld # 开启自启动
- View the status of mysql
systemctl status mysqld
3. Log in to mysql and change the password
- View the default password generated for the root user during mysql installation
cat /var/log/mysqld.log | grep -i "temporary password"
cat /var/log/mysqld.log | grep -i "temporary password"
- Use the initial password to log in to mysql
mysql -uroot -pxxxxx
- No operations can be performed at this time. Once you do, you will be prompted to reset the root password first.
- Since I have very low requirements for security rules, I set it to low level and set the minimum number of passwords to 6.
set global validate_password_policy = 0;
set global calidate_password_length = 6;
- Use
alter user
setup password again
alter user 'root'@'localhost' identified by '123456';
- Record the pits stepped on to reset the password
- According to the prompts, use to
alter user
reset the root password, but the rules for prompting the password are too simple! ! !
- According to the prompts, use to
alter user 'root'@'localhost' identified by '12345'
2. Check the information and say that you need to check the password rules before you can better set the password. —— As a result, it is prompted to reset the password first
show variables like "validate_password"
- Finally, this blog solved my problem: Solve the problem of Your password does not satisfy the current policy requirements. in MySQL 5.7
- After setting, use the
exit
command to exit the mysql interactive interface, and successfully log in with the new password!
mysql -uroot -p(your_new_password)
4. Common mysql service commands
systemctl start mysqld # 开启mysql服务
systemctl stop mysqld # 关闭mysql服务
systemctl restart mysqld # 重启mysql服务
systemctl status mysqld # 查看mysql服务的状态