简体   繁体   中英

How to recover/Change MySQL Password

Yesterday Everything was working fine. Today when i start mysql its start giving me following error message

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I don't know when and how it sets password.

Now i am trying to set password, but its not updating it.

I am using following steps to recover password.

  1. Stop Mysql Service
  2. Write this in cmd:

C:\\Program Files\\MySQL\\MySQL Server 5.5>mysqld.exe --defaults-file="my.ini" --init-file="d:\\mysql-init.txt" --console

It start showing me progress but stop responding after this message

160504 18:01:54 [Note] Server socket created on IP: '0.0.0.0'.
160504 18:01:54 [Note] Event Scheduler: Loaded 0 events
160504 18:01:54 [Note] mysqld.exe: ready for connections.
Version: '5.5.38'  socket: ''  port: 3306  MySQL Community Server (GPL)

I waited for more than 10 minutes but its not showing any progress after this..

Kindly guide me how to resolve this problem.

Thanks

Follow step-by-step to change mySQL root password.

1) Log on to server as Administrator.

2) Stop the MySQL service or kill it [mysqld-nt.exe] from Task manager [if not worked from services.msc].

3) Create a text file containing the following statements:

UPDATE mysql.user SET Password=PASSWORD('test@123') WHERE User='root'; FLUSH PRIVILEGES;

4) Save the file. For this example, the file will be named C:\\mysql-init.txt.

5) Get to the command prompt: Start the MySQL server with --init-file option.

6) C:> C:\\mysql\\bin\\mysqld-nt --init-file=C:\\mysql-init.txt

Stop the mysql service

Edit the my.ini file or my.cnf file

Find the [mysqld] section in the ini file and add this line directly after the section [mysqld]

skip-grant-tables

Restart the mysql service.

Open the MySQL console

Now we are going to reset the password for the root user, of course this could be used to reset any users password.

Enter the following 2 commands at the mysql> command prompt, each with a semi colon at the end of a line, and press ENTER after each line to issue the command to mysql.

Pre MYSQL version 5.7

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

Post MYSQL version 5.7 the column name changed

UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

Note that the update may report that it has updated more than one row, that because there are actually 3 user accounts with the userid of 'root' each with a different domain ie 127.0.0.1, localhost and ::1

Now enter quit at the mysql command prompt to exit mysql.

Stop the mysql service

Edit the my.ini file or my.cnf file

Find the {mysqld] section in the ini file and Remove the skip-grant-tables parameter we added earlier.

DO NOT Leave this parameter in the ini file its a HUGH security hole.

Restart the mysql service.

You should now be able to login with phpmyadmin using the userid 'root' and the new password you have just set for that user.

  1. Stop mysql service

    /etc/init.d/mysql stop

  2. Skip mysql privilegies

    /usr/bin/mysqld_safe --user=mysql --skip-grant-tables

  3. Open cmd and write

    mysql

  4. Now let's use our database with this command:

    use MY_DATABASE_NAME;

  5. Update field password of the root user with the next command:

    UPDATE user SET Password=PASSWORD('ourpassword') WHERE user='root';

  6. Exit command.

    exit

  7. Initiate a new database session.

    mysql -u root -p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM