MySQL5.7 5 ways to reset password after initialization

Source: Internet
Author: User
Tags flush lowercase reserved

Introduction: Due to several times after the installation of MySQL5.7 has been plagued by resetting the password, so deliberately organized the method of reset

Installing MySQL5.7

[[email protected] db]# ll the following RPM installation package can be downloaded from anywhere total 402356-rw-r--r--1 root root 24744 Nov libaio-0.3.109- 13.el7.x86_64.rpm-rw-r--r--1 7155 31415 25106088 Mar 5 10:24 mysql-community-client-5.7.22-1.el7.x86_64.rpm-rw-r--r-- 1 7155 31415 3781636 Mar 5 10:24 mysql-community-devel-5.7.22-1.el7.x86_64.rpm-rw-r--r--1 7155 31415 2239868 Mar 5 10:24 mysql-community-libs-5.7.22-1.el7.x86_64.rpm-rw-r--r--1 7155 31415 172992596 Mar 5 10:25 Mysql-community-server-5.7.22-1.el7.x86_64.rpm[[email protected] db]# [[email protected] db]# RPM-IVH *. RPM--nodeps--forcewarning:mysql-community-client-5.7.22-1.el7.x86_64.rpm:header V3 DSA/SHA1 Signature, key ID   5072e1f5:nokeypreparing ... ################################# [100%]updating/installing ... 1:mysql-community-libs-5.7.22-1.el7################################# [20%] 2:mysql-community-client-5.7.22-1.e##          ############################### [40%] 3:libaio-0.3.109-13.el7  ################################# [60%] 4:mysql-community-server-5.7.22-1.e################################# [80% ] 5:mysql-community-devel-5.7.22-1.el################################# [100%] start mysql[[email protected] db]# Systemctl start mysqld Get a randomly generated password from the log [[email protected] db]# grep password/var/log/mysqld.log 2018-07-15t09:0 1:09.735836z 1 [Note] A temporary password is generated for [email protected]: vifg8pwf+,lu[[email protected] D b]# mysql-uroot-pvifg8pwf+,lumysql: [Warning] Using a password on the command line interface can be insecure.  Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 2Server version:5.7.22copyright (c), 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement. No action is allowed after login mysql> show Databases; Error 1820 (HY000): Unknown error 1820mysql> select * from MySQL;  ERROR 1046 (3d000):

Method 1: Use Alter to modify

mysql> ALTER User User () identified by ' [email protected]#$ '; Query OK, 0 rows Affected (0.00 sec) mysql> ALTER USER ' root ' @ ' localhost ' identified by ' tom579#$%^& ';  #针对localhostQuery OK, 0 rows Affected (0.00 sec) or first turn off its password policy modification mysql> SELECT @ @validate_password_length; Error 1820 (HY000): Unknown error 1820mysql>  ALTER User User () identified by ' 12345678 '; Query OK, 0 rows Affected (0.00 sec) Validate_password_policy has the following values: Policytests Performed0 or LOWLength1 or mediumlength; Numeric, lowercase/uppercase, and special characters2 or stronglength; Numeric, lowercase/uppercase, and special characters; Dictionary file defaults to 1, which is medium, so the password you just started must match the length and must contain numbers, lowercase or uppercase letters, special characters.

Method 2: Use Set password

mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' [email protected]&#@ ');  #第一次也要符合密友复杂度Query OK, 0 rows affected, 1 Warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows Affected (0.00 sec)

Method 3: Use the update

mysql> UPDATE mysql.user SET authentication_string = PASSWORD (' [email protected]&%! '), password_expired = ' N ' wher E User = ' root ' and Host = ' localhost '; Query OK, 1 row affected, 1 Warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows Affected (0.00 sec)

method 4 : Using mysql_secure_installation

[[email protected] db]# mysql_secure_installation securing the MySQL server deployment. Enter password for user root: [email protected]&%! The ' Validate_password ' plugin is installed on the server. The subsequent steps would run with the existing configurationof the plugin. Using existing password for root. Estimated strength of the password:100 change the password for root? (Press y| Y for Yes, any other key for No): ynew password:tom579#$%^&re-enter New password:tom579#$%^&estimated strength Of the password:100 do you wish to continue with the password provided? (Press y| Y for Yes, any other key for No): yby default, a MySQL installation have an anonymous user,allowing anyone to logs into MyS QL without has to havea the user account created for them. This was intended only fortesting, and the installation go a bit smoother. You should remove them before moving into a productionenvironment. For security should yesremove anonymous users? (Press y| Y for Yes, any and key for NO): No ... skipping. Normally, Root should only is allowed to connect from ' localhost '. This ensures, someone cannot guess atthe root password from the network. For security should yesdisallow root login remotely? (Press y| Y for Yes, any other key for No): no ... skipping. By default, MySQL comes with a database named ' Test ' Thatanyone can access. This was also intended only for Testing,and should was removed before moving into a productionenvironment. To be safe should yesremove te St Database and access to it? (Press y| Y for Yes, any other key for No): no ... skipping. Reloading the privilege tables would ensure that all changesmade so far would take effect immediately. Reload privilege tables now? (Press y|  Y for Yes, any, and key for No): Ysuccess.all done!

method 5 : Skip Authorization list skip-grant-tables

[[email protected] db]# mysqlerror 1045 (28000): Unknown error 1045[[email protected] db]# vim/etc/my.cnf #使用完 After removing [mysqld]skip-grant-tables=1 restart MySQL, then modify [[email protected] db]# systemctl Restart mysqld[[email   Protected] db]# Mysqlwelcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 2Server version:5.7.22 mysql Community Server (GPL) Copyright (c) #, 2018, Oracle and /or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> set password = password (' [email protected]%& '); Error 1290 (HY000): Unknown error 1290mysql> ALTER USER ' root ' @ ' localhost ' identified by ' tom579#$%^& '; Error 1290 (HY000): Unknown error 1290mysql> flush privileges; Query OK, 0 rows Affected (0.00 sec) mysql> Set password = password (' [EMAIL PRotected]%& '); ERROR 1133 (42000): mysql> ALTER USER ' root ' @ ' localhost ' identified by ' tom579#$%^& '; Query OK, 0 rows affected (0.01 sec) mysql> Set password for [email protected] = password (' 123456 '); Query OK, 0 rows affected, 1 Warning (0.00 sec)

Summary
A. mysql5.7 will produce a random password in the/var/log/mysql.log after installation, and do not perform any action without changing the password
B. The password string in the user table of mysql5.7 is modified to authentication_string
C. Change the password policy change is 1 (intermediate), so set up to conform to the rules
D. Skipping authorization columns and not affected by password policy

MySQL5.7 5 ways to reset password after initialization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.