Mysql database version 5.7 password modification details (centos7)
Premise: mysql version 5.7 Linux version Red Hat centos7 goal: set up a MYSQL database server and set the local login password of the database administrator to 123456
-1. Installation strategy
-2. Check the installation
~ # rpm-qa | grep 'mysql' to check whether it is installed
~ # rpm-qc mysqld to view all configuration files of the service
/ etc/my.cnf
~ # cat / etc/my.cnf (various parameters defined by the configuration file will vary with different versions)
...
Datadir=/var/lib/mysql-find the default location for storing data
Log-error=/var/log/mysqld.log-find the default log
...
-3. Start the service # systemctl start mysqld
-4. Log in with the initial password (version 5.7 is stored in the log by default)
~ # grep 'password' / var/log/mysqld.log
Password is generated for root@localhost: Y2d > EdirOfVs
~ # mysql-u root-p 'y2d > EdirOfVs' remember that passwords are random
-5. Change the password (if you remember the initial password, at least it is highly secure, )
Method 1:
The mysql > set global validate_password_policy=0; policy is set to 0, which means only the password length is checked
The default password length for mysql > set global validate_password_length=6; is 6
Mysql > alter user root@ "localhost" identified by '123456; modification completed
Method 2: this method should follow policy 1 to set a new password
0/LOW: check only the length
1/MEDIUM: check length, numbers, case, special characters
2/STRONG: check length, number, case, and special character dictionary files.
~ # mysqladmin-hlocalhost-uroot-p password "New password"
Enter password: original password
-6. Forget your password? Don't worry. Look down.
~ # systemctl stop mysqld shut down the service first
~ # vim / etc/my.cnf modify configuration file
[mysqld]
Skip-grant-tables adds this line
: wq
~ # systemctl restart mysqld restart the service
-7. Log in and set a new password
~ # mysql go straight in
Mysql > update mysql.user set authentication_string=password ('654321') where user='root' and Host = 'localhost'
Mysql > flush privileges
Mysql > quit
~ # vim / etc/my.cnf exit mysql and modify the configuration file again
[mysqld]
# skip-grant-tables comment out or delete the previously modified ones
: wq
~ # systemctl restart mysqld modify configuration file remember to restart
~ # mysql-uroot-pendant 654321 'pull on ok
Mysql >
For criticism and correction, please leave a message in the comment counter, and I will modify it when I see it. HAHA