You may receive the “Access denied for user ‘root’@’localhost'” message while accessing mysql from the command prompt.
The error message states that the Mysql password for user ‘root’ is incorrect and need to reset the password using the skip-grant-tables method.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
How to reset root Mysql password in Linux?
First stop the mysql service
# /etc/init.d/mysql stop
Make sure all the mysql processes are stopped by executing the killall command
# killall -9 mysqld
Next, start mysql is safe mode i.e. the privileges will be skipped while connecting to the mysql server
# /usr/bin/mysqld_safe --skip-grant-tables &
now, connect to your Mysql prompt using the ‘mysql’ command
# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23056 mysql>
Goto the ‘mysql’ database
mysql> use mysql;
Now set a password for user ‘root’
mysql> update user set password=PASSWORD("passhere") where user='root';
OR you can also set a blank password for user ‘root’
mysql> update user set password=PASSWORD("") where user='root';
Once done, reload privileges and quit
mysql> flush privileges; mysql> quit
Now, restart the mysql service
# /etc/init.d/mysql restart
and you should be able to connect to your mysql server:
# mysql OR # mysql -uroot -p
October 11th, 2011 at 4:56 pm
Thank You soo much!!!!! I have been struggling with this blasted problem for days and now I can finally enter mysql! Such a beautiful and extremely well written tutorial on how to solve this problem!! Whoever you are, THANK YOU!:-)
October 22nd, 2011 at 8:16 am
Welcome 🙂