Forgot your password mysql how to do?

mysql for a long time useless, do not know what the original password, and would like to enter the mysql database how to do it? There are two ways to reset password mysql: 1, directly modify the command line; 2, modify my.ini file.

method one:

          1. Turn off the MySQL service is running
          2. Open a DOS window, go to the mysql \ bin directory
          3. Enter mysqld --skip-grant-tables Enter --skip-grant-tables means that the MySQL service start time skip certification authority table
          4 and then open a DOS window (DOS window because that just can not move), go to the mysql \ bin directory 
          5. enter the mysql enter, if successful, will appear MySQL prompt>
          6. connect privileges on the database: MySQL use;
          6. The change password: Update User SET password = password ( "123") WHERE User = "the root"; 
             mysql5.7 above -> UPDATE user SET authentication_string = pASSWORD ( "123") WHERE User = "root ";
          7. refresh permission (must step): flush privileges; 
          8. exit exit. 
          9. log off the system, re-entry, using the username root and the password just set up 123 new login.

Method Two:

         1. Locate the my.ini file (this file is a hidden file by default is invisible, direct input folder location C: \ ProgramData \ MySQL \ MySQL Server 5.7 will be able to see the my.ini file)

         2. Open file my.ini, in [mysqld] field my.ini added: skip-grant-tables, then save. (If the file being used can not be saved because of a permissions problem, first copy the file out of the re-examination after the completion of modifications to its original position)

        3. Enter an administrator enter cmd 

        net stop mysql
        net start mysql

        4. Enter the mysql installation directory, mine is C: \ Program Files \ MySQL \ MySQL Server 5.7 \ bin, enter mysql -u root -p 123456, you can successfully connect to the database;

        5. Modify the mysql password

                flush privileges; (first refresh authority table, otherwise there is no way to save the new password)

                update user set password=password('新密码') WHERE User='root';

        6. Exit mysql, enter the exit;

        7. my.ini file, add the "skip-grant-tables", and save.

Guess you like

Origin www.cnblogs.com/yuhou/p/11847750.html