Install MySQL on centos 7 and solve the password reset pit

  • I like that all operations are under root authority. If you are prompted to have no authority, please add sudoor switch to a rootuser.
  • 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

Insert picture description here

  • Check if mysql already exists in your system
rpm -qa | grep -i mysql
  1. I have already installed it, so I found out that it really exists.
    Insert picture description here
  2. 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

Insert picture description here

2. Install mysql

  • Install the latest mysql, there will be a corresponding prompt message after installation
yum -y install mysql-community-server

Insert picture description here

  • Start mysql and turn on self-start after boot.
systemctl start mysqld   # 开启mysql服务
systemctl enable mysqld  # 开启自启动
  • View the status of mysql
systemctl status mysqld

Insert picture description here

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.
    Insert picture description here
  • 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 usersetup password again
alter user 'root'@'localhost' identified by '123456';

  • Record the pits stepped on to reset the password
    1. According to the prompts, use to alter userreset the root password, but the rules for prompting the password are too simple! ! !
alter user 'root'@'localhost' identified by '12345'

Insert picture description here
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"
  1. 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 exitcommand to exit the mysql interactive interface, and successfully log in with the new password!
mysql -uroot -p(your_new_password)

Insert picture description here

4. Common mysql service commands

systemctl start mysqld    # 开启mysql服务
systemctl stop mysqld     # 关闭mysql服务
systemctl restart mysqld  # 重启mysql服务
systemctl status mysqld   # 查看mysql服务的状态

Guess you like

Origin blog.csdn.net/u014454538/article/details/108026193