Mysql – Cannot login to thesql after setting incorrect thesql privileges/host

hosthostsMySQLusers

On CentOS 5.x I used webmin panel and I was in mysql settings, I was trying to allow "root" to login from my home ip in addition to localhost.
In the hosts list I had "any" or "localhost", I tried to make it "localhost,84.xx.xx.xx" thinking it will allow me to login from my local computer with mysql administrator program.

After I saved the entered data I cannot do much on mysql

Webmin says DBI connect failed : Access denied for user ''@'localhost' to database 'mysql'

In SSH mysql says ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

My guess is that mysql doesn't allow root to connect from any host anymore because I entered incorrect hosts.

I tried uninstalling and reinstalling mysql but no change.
Is there a way to reset this? I have no database data, I can delete all if needed.

Thanks.

Best Answer

Log in at a terminal as root and stop the mysql daemon.

/etc/init.d/mysqld stop

Then start up the mysql daemon and skip the grant tables which stores the passwords and other priviledge information

mysqld_safe --skip-grant-tables &

You should see mysqld start up successfully. Now you should be able to connect to mysql without a password.

mysql --user=root mysql

and then update the relevant information:

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

and then restart the mysql daemon as you would normally do

/etc/init.d/mysqld restart

Also take a look at the MySQL documentation to help you out if you get stuck

Related Topic