How to reset forgotten mysql root password?

Hi All,

I just found one thread on this forum on this subject here:

Forgot MYSQL password root | Unix Linux Forums | Web Programming

but unfortunately the issue was not resolved.

I have the same problem with the same error message.
The background is that I built a Solaris 11 x86 server (using Solaris 11 Live DVD hard drive install option) for using as a test web server on my local LAN. I was amazed at how simple this was to "throw on" MySQL, Apache, PHP, and other prerequisites. I then installed Wordpress and it just worked. Unfortunately, in the rush to get it running I didn't note the MySQL root password that I used.

NOTE TO MODERATOR: If this would get a better response on a forum other than Solaris please do move it.

I haven't looked for or tried solutions found on Google yet. I just thought I'd put it on this great forum first.

I have modified the role of the root user to "normal". Obviously, I have physical hardware access, console root login access, etc.
Anybody know how to get back into MySQL in these circumstances?
Thanks in advance

But you have root access to the machine? If so, then you can simply run "mysql" as root user, then change whichever user's password you need to change.

Perhaps I haven't made myself clear.

It's the MySQL database root password that I'm trying to change (not the password of the MySQL system user).

Yes, I can login to the system as root. I know how to change any user's password. I've told many a member on this forum how to boot from DVD and reset root passwords.

I know plenty about Solaris but I'm dumb on MySQL.

You will need to spell it out clearly as I'm no MySQL expert.

Thanks.

What happens when you execute "mysql" as Solaris root user? Do you get MySQL prompt?

Yes, I do.

Then you should be able to do this (from https://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html

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

That gives the error:

 
 ERROR 1046 (3D000): No database selected
 Query OK, 0 rows affected (0.00sec)
 

I've tried to reinstall Wordpress on the platform but it asks for password for root@localhost but I don't remember what I set it to when I installed MySQL.

If I run

 
 /usr/mysql/5.1/bin/mysql_install_db
 

it also asks for password for root@localhost and I've forgotten it.

Am I correct in assuming that MySQL database user password are stored inside the database (like Oracle)?

On install of Solaris 11, it set me up a personal userid/password and the root role password was the same password. Since installation I've modified the root role to a normal user and then changed the root user password. Would any of that have screwed up or changed the MySQL authentication? If database user passwords are stored inside the database then I assume not?

I need to go and study that link you posted and understand MySQL much better. Homework needs to be done.

What does this show in mysql prompt:

show databases;
1 Like
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| mysql              | 
| test               | 
+--------------------+
3 rows in set (0.02 sec)

mysql> 

If you follow the instructions bartus11 kindly posted for you in his post #6, you should have no trouble resetting the mysql root password.

Did you do this? (from bartus11's link)

1 Like

Thanks guys. That worked.