How to recover MYSQL password with mysqld error

Asked

Viewed 558 times

2

today was wanting to change the root password of my mysql that is on a windows server 2008. However I ended up forgetting the password, searching checked several techniques stopping mysql and running the command mysqld-nt ...

However this error occurs:

C:\Program Files\MySQL\MySQL Server 5.6\bin>
C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld-nt
'mysqld-nt' is not recognized as an internal or external command,
operable program or batch file.

Someone can help me?

  • 1

    If the nt is the argument, a space after the mysqld if not he will try to find an executable with that name.

  • Okay @rray, I tried to perform the commands, see: C: Program Files Mysql Mysql Server 5.6 bin>mysqld -nt 2016-07-06 17:20:20 0 [Warning] option 'new': Boolean value’t' wasn’t recognize d. Set to OFF. 2016-07-06 17:20:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is depreca Ted. Please use --explicit_defaults_for_timestamp server option (see documentati on for more Details). 2016-07-06 17:20:20 0 [Note] mysqld (mysqld 5.6.25) Starting as process 5048 ...

1 answer

2

First of all, the error presented is simply because you either do not have an executable with this name on the machine, or you are not running with the correct path.

Once you have located the correct executable, let’s go to the password question (in the case of Windows you don’t even need to, just do everything by the Services panel, the services.msc).

There is a possibility that is to use a boot option for this:

--skip-grant-tables

The precaution to take is that this option makes Mysql accept as root any user that connects, so it should only be used so that you have access to DB and solve the password problem.

To use via command line, just stop the instance and run manually with the parameter --skip-grant-tables, fix the DB by putting the desired password in the way you find most convenient, and after changing the password restart the service normally without the --skip-grant-tables)

In Windows, you can run services.msc and put the parameter in the initialization options of the respective instance and restart the service (and remove right in after password exchange, restarting the service normally).

It is advisable to block third party access to the machine during maintenance, if you choose this solution.


Extra considerations:

If you are going to make the change locally, using this parameter is of great value:

 --bind-address=127.0.0.1

This makes the instance respond only to the local address, leaving the operation safer.


If you need to specify where my.ini or equivalent file, since it is calling the server manually, has this option:

--defaults-file=/etc/my.ini


Alternative with startup script

Originally this was a user response Bruno Bermann, but for some reason was removed. I didn’t test it, but in theory it makes sense. It’s here as a reference for those who want to test.

In general lines, you can specify a startup file like this:

mysqld --init-file="C:\\Caminho\\init.txt"

and, in theory, on this path could have something like

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

to change the desired password.

  • Hello @Bacco I am trying via command line, I do the following: 1. I stop the service called Mysql56. 2: run via command line mysqld-nt --Skip-Grant-Tables. 3 run the command mysqld --init-file="C: init.txt" and then close the mysqld process and start Mysql56 again but not modified the password :/

  • 1

    or use one or the other. it makes no sense to use init if you will skip the Grants.

  • understood, stopped the service and gave the command C: Program Files Mysql Mysql Server 5.6 bin>mysqld --init-file="C: init.txt" 2016-07-06 20:37:30 0 [Warning] TIMESTAMP with implicit DEFAULT value is depreca Ted. Please use --explicit_defaults_for_timestamp server option (see documentati on for more Details). 2016-07-06 20:37:30 0 [Note] mysqld (mysqld 5.6.25) Starting as process 5064 ... But he got caught up in it! :(

  • My original suggestion is you skip the Grant table and change the password as you are used to, according to the first part of the answer, and forget this init thing. As for the other errors, it is a problem in your Mysql configuration.

  • You need to see if it’s not the case to back up the data, test the backup to see if it’s ok, and then reinstall the service, if it’s a very outdated server.

  • 1

    Good news, it worked, you can for the service, enter mysqld --Skip-Grant-Tables and then access mysql and change the password with the following "UPDATE mysql.user SET Password=PASSWORD('Senhanova') WHERE user='root'; FLUSH PRIVILEGES;" Changed lines appeared and I restarted the Mysql56 service but could not log in.

  • You need to see if root is allowed to log in to any IP, and the ideal way to change the password and host is to use the traditional Grant command, and not to move the user table directly.

  • I did everything right, I can log in while changing the password, but when I start the service again mysql simply does not recognize my password :/ @Bacco

  • You allowed access by your host when changing the password?

  • What do you mean? Can you explain me? I changed so SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxxxxx');

  • I would suggest you read the above recommendations more carefully, and study the mysql Grant command. It specifies user name, privileges, password and HOST. It is no use to know the user’s password and name if the IP/Host you are using is not authorized for that account. If you want the account to be accessed from any machine, you need to put a % in place of the host. Here are some examples of how to change with Grant or with update: http://serverfault.com/questions/483339/changing-host-permissions-for-mysql-users#483364

  • 1

    Unfortunately this time only managed to solve at the time fully reinstalling sql. But thanks for the attention @Bacco

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.