[MDEV-29712] Cannot Reset MariaDB Root password Created: 2022-10-05  Updated: 2022-10-11  Resolved: 2022-10-11

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.8
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Mike Jacobs Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: authentication, root
Environment:

win 10 pro 21H2 on i9 with 32gb RAM & 2x2TB ssds



 Description   

Somehow I've buggered up my password into the MariaDB database I was last working in back in August when I described a potential auto increment bug,
see MDEV-29416

So I'm trying to reset the password following the instructions I found here:
https://mariadbtips.com/mariadb-reset-root-password/

but it fails at my attempt to login as root. The command window script shows the full sequence:

*****************************
C:\Program Files\MariaDB 10.8\bin>net stop mariadb
The MariaDB service is stopping..
The MariaDB service was stopped successfully.

C:\Program Files\MariaDB 10.8\bin>mysqld --skip-grant-tables --skip-networking --shared-memory
2022-10-05 15:51:36 0 [Note] mysqld (server 10.8.3-MariaDB) starting as process 7916 ...

C:\Program Files\MariaDB 10.8\bin>mysql -u root
ERROR 2002 (HY000): Can't connect to server on 'localhost' (10061)

[my comment: I've seen this error many time before and its always been because the MariaDB service hasn't started, so I start it manually thus:]

C:\Program Files\MariaDB 10.8\bin>net start mariadb
The MariaDB service is starting..
The MariaDB service was started successfully.

C:\Program Files\MariaDB 10.8\bin>mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

*****************************

obviously, at that point I can't go any further, so I'm out of options.

What am I missing?



 Comments   
Comment by Mike Jacobs [ 2022-10-05 ]

little bit extra:

just retried the mysqld command and, using Process Hacker, went looking for the PID it claims to be starting. Nothing appears. And, unlike the net stop or net start commands, as you can see from the command window sequence, no confirmation is displayed, so it looks like the mysqld command is failing but I've no idea how to troubleshoot that...

Comment by Vladislav Vaintroub [ 2022-10-05 ]

The tutorial that you're following, it is simply incorrect

a) --shared-memory does not exist in MariaDB since IIRC 10.3. The server thus can not start, but you do not see that , because the failed startup messages are in the error log, not on the console. The failed startup that you do not see, would end up with

2022-10-05 23:12:22 0 [ERROR] mysqld: unknown option '--shared-memory'
2022-10-05 23:12:22 0 [ERROR] Aborting

b) If you do not like the server to be exposed on the internet and limit to local machine only, add --bind-address=127.0.0.1 parameter.

c) Do not use --skip-networking
d) Add --console to the server parameter, to see how it actually starts, on the console, rather than in the error log.

The full technology demonstration.

1. From elevated command prompt

.\mysqld.exe --console --skip-grant-tables --bind-address=127.0.0.1

Make sure server starts, if it does, it writes something like

2022-10-05 23:43:30 0 [Note] Server socket created on IP: '127.0.0.1'.
2022-10-05 23:43:30 0 [Note] InnoDB: Buffer pool(s) load completed at 221005 23:43:30
2022-10-05 23:43:30 0 [Note] mysqld: ready for connections.

on the console.

If it does not start, maybe you need to add "--defaults-file=C:\path\to\datadir\my.ini" to wherever the my.ini is

2. Set password and shutdown server

from another cmd window, or powershell, or whatever, execute

.\mysql.exe -uroot -e "flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED BY 'my_secret';flush privileges;shutdown"

with your new password instead of my_secret in IDENTIFIED BY

This batch command will also stop the server you started previously.

3. restart the service, and connect with the new password

Comment by Mike Jacobs [ 2022-10-06 ]

Thanks Vadislav

Looks like a comprehensive reply. (Don't know if there's a bug in the message system, but I got 6 copies of your message, although I noticed that the last one was an edit, so probably legit)

The first part worked. Your version on the mysqld.exe command started the server and I got the kind of response you suggested. However, the second part (in a new elevated cmd window) still failed like the original

Here's the exact script with a dummy password I generated for the purpose of this reply:

C:\Program Files\MariaDB 10.8\bin>mysql.exe -uroot -e "flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED BY 'XRs8SSixKmowSMsWcLL8wui6p';flush privileges;shutdown"
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I also tried inserting a space in "-uroot" as, in all other command lines I've seen (and used) it has appeared as -u root

but that made no difference.

Comment by Mike Jacobs [ 2022-10-07 ]

OK, this just got weird.

It does NOT appear to be a password issue at all

I just discovered that if I use the following

mysql.exe --user=root --password

it prompts me for the password, I paste in the password. It lets me in.

But if I use

mysql.exe --user=root --password=the same password I just pasted in above

I get the Access denied message.

Anyone come across that behaviour before?

Anyone got any ideas as to probable cause and possible fix?

Comment by Mike Jacobs [ 2022-10-11 ]

Fixed, eventually, by uninstalling and reinstalling (and taking opportunity to step up to 10.9.3). The cause was almost certainly a reserved character in the password (probably the % symbol) which Maria can handle but the windoze command line couldn't.

First issue I've "closed" in this forum. Not obvious how I mark it as such.

Generated at Thu Feb 08 10:10:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.