LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Lost root access in MySQL (http://www.linuxquestions.org/questions/linux-software-2/lost-root-access-in-mysql-486785/)

telakenesys 09-25-2006 08:23 AM

Lost root access in MySQL
 
Hi everyone.

I have a problem with the MySQL server I have running on Fedora Core 5.

I accidentally dropped 'root' from the user table in the mysql database. As a result I can't do much at all. (I have no other privileged user).

Iím sorry, but I am sure this question has probably been asked a million times but I have spent hours scouring forums looking for a way to fix this with no luck.

Everything that I try, returns:
Access denied for user ''@'localhost' to database 'mysql'


:newbie:

odcheck 09-25-2006 09:07 AM

What if you enter a terminal as ROOT
then
Code:

mysql -u root mysql
and then
Code:

mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
where new_password is exchanged by you desired new pw


telakenesys 09-25-2006 06:38 PM

Access denied for user ''@'localhost' to database 'mysql'

got_nix 09-25-2006 07:44 PM

Quote:

Originally Posted by odcheck
What if you enter a terminal as ROOT
then
Code:

mysql -u root mysql
and then
Code:

mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password');
where new_password is exchanged by you desired new pw


kinda right however you need to skip the grant tables when you restart mysql

this has save me once or twice here yo go

1. Take down the mysqld server by sending a kill (not kill -9) to the mysqld server. The pid is stored in a `.pid' file, which is normally in the MySQL database directory:

Code:

    shell> kill `cat /mysql-data-directory/hostname.pid`
You must be either the Unix root user or the same user mysqld runs as to do this.
2. Restart mysqld with the --skip-grant-tables option.
3. Set a new password with the mysqladmin password command:

Code:

      shell> mysqladmin -u root password 'mynewpassword'
4. Now you can either stop mysqld and restart it normally, or just load the privilege tables with:

Code:

shell> mysqladmin -h hostname flush-privileges
5. After this, you should be able to connect using the new password.

Alternatively, you can set the new password using the mysql client:

1. Take down and restart mysqld with the --skip-grant-tables option as described above.
2. Connect to the mysqld server with:

Code:

shell> mysql -u root mysql
3. Issue the following commands in the mysql client:

Code:

      mysql> UPDATE user SET Password=PASSWORD('mynewpassword')
          ->            WHERE User='root';
      mysql> FLUSH PRIVILEGES;

4. After this, you should be able to connect using the new password.
5. You can now stop mysqld and restart it normally.

telakenesys 09-25-2006 08:56 PM

When I try the first method returns:
mysqladmin: unable to change password; error: 'Access denied for user ''@'localhost' to database 'mysql''
and the second one cames back with:
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
I think that i might just have to try to back everything up and start from sctratch.

telakenesys 09-27-2006 06:18 AM

I have had a thought. If I were to delete the mysql database files and run mysql_install_db ?

Will this recreate the database that I need with root access and no password?

got_nix 09-27-2006 10:19 AM

Quote:

Originally Posted by telakenesys
I have had a thought. If I were to delete the mysql database files and run mysql_install_db ?

Will this recreate the database that I need with root access and no password?

not a bad idea.. yeh. a total overhall on the db should work becuase it comes with the default root root uname and pass.

telakenesys 09-27-2006 07:07 PM

Thanks guy for all the help. I ended up getting it working by deleting the database and going again. Didn't even lose anything in the other databases.

But now after all that trouble, the app i was trying to get working is no good.
Thanks again guys.

got_nix 09-27-2006 07:32 PM

No problem I'm Glad you got it up and running

abhay_bc 02-23-2011 04:48 AM

fixed
 
I had the same problem and this is what I did to fix it -

stopped mysql service
started mysql with --skip-grant-tables option
logged in mysql with no username/password ( just mysql command )
inserted a row with user=root , host=localhost and all required privileges = 'Y'
executed flush privileges
restarted mysqld service

It took care of my problem. Did not have to reinstall mysql.


All times are GMT -5. The time now is 10:22 AM.