4

I have forgotten my "Root" password of "MySQL" on my Windows machine. I tried using this link, But getting the error message(Pic attached). Can anyone help me out from this?

enter image description here

Steps Followed:-

1:- Stopped "MySQL process" in my computer service section.

2:- Created a .txt file having data ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

3:- Renamed the file to mysql-init.txt & saved into C drive.

4:- Opened command prompt & used the command C:> cd C:\Program Files\MySQL\MySQL Server 5.7\bin

5:- Then used C:> mysqld --init-file=C:\mysql-init.txt

After then I am getting this error message in my console.

9
  • Do you have data that you need to keep? Commented Mar 25, 2017 at 7:29
  • I see that you’re using v 5.7. There appears to be a difference in procedure between 5.7.5 and 5.7.6. Could you outline the steps (edit your question) that you followed? Commented Mar 25, 2017 at 7:33
  • Hi Mango, Thanks for quick revert. I don't want to keep any data that I had created before. Simply when I am trying to create a new database I am facing this issue. Commented Mar 25, 2017 at 7:34
  • Without looking at your system, I can’t say what’s actually gone wrong, but the first error message suggests that something is missing. If worse comes to worse, you can uninstall and start again. However, I strongly recommend that you also install MySQL WorkBench, which is a free GUI from Oracle. Commented Mar 25, 2017 at 7:37
  • Hey Manngo, Now the followed steps are edited in my question section. Already I have tried with the Uninstall-Install process. But seems it is not working out. Commented Mar 25, 2017 at 7:43

2 Answers 2

8

Here a little bit twist with MySQL Community Server 5.7 I share some steps, how to reset MySQL 5.7 root password or set password. It will work CentOS 7 and RHEL7 as well.

  1. Stop your databases
service mysqld stop
  1. Modify /etc/my.cnf file add skip-grant-tables
vi /etc/my.cnf
[mysqld] 
skip-grant-tables
  1. Start MySQL
service mysqld start
  1. Select MySQL default database
mysql -u root
mysql> use mysql;
  1. Set a new password
mysql> update user set authentication_string=PASSWORD("yourpassword") where User='root';
  1. Restart MySQL database
service mysqld restart
mysql -u root -p
Sign up to request clarification or add additional context in comments.

Comments

1

For Linux This process is if you have root access on your server

First things first. Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.

mysqld_safe --skip-grant-tables

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

mysql --user=root mysql

update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;

Now kill your running mysqld, then restart it normally. Let me know if you have a problem

For windows

  1. Stop your MySQL server completely. This can be done from Wamp(if you use it), or start “services.msc” using Run window, and stop the service there.

  2. Open your MS-DOS command prompt using “cmd” inside the Run window. Then go to your MySQL bin folder, such as C:\MySQL\bin. Path is different if you use Wamp.

  3. Execute the following command in the command prompt:

    mysqld.exe -u root --skip-grant-tables
    
  4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

  5. Go to your MySQL bin folder again.

  6. Enter “mysql” and press enter.

  7. You should now have the MySQL command prompt working. Type “use mysql;” so that we switch to the “mysql” database.

  8. Execute the following command to update the password:

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

    However, you can now run almost any SQL command that you wish.

After you are finished close the first command prompt, and type “exit;” in the second command prompt.

You can now start the MySQL service. That’s it.

Take a look at this answer for more explanation from the discussions

6 Comments

How is it not working out, have you looked at my edit
hey, I have not seen your edits.Apologize for this.After step-2 when saving the configuration file ** my.ini** it is showing 1:- my-ini already exists. Do you want to replace it. When I am clicking on Yes. The dialogue-box is showing access denied.
I have updated my answer so that you do not have to deal with files but only with command prompt. Hope i have helped you out.
Hey Dougulas, Thanks for your great effort for helping.Unfortunately, my system was having only ready only access to change the root password. So I followed the following steps. Uninstalled the complete MySQL package. Then manually deleted Program files--> MySQL + Programme data__> MySQL (+), C:\Users\User\AppData\Roaming\MySQl. Then Installed again. Now it is completly running fine. Thanks for your help again.
Thats great @Jyotiranjan, glad it worked out for you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.