MySQL: Access denied for user

MySQL Error : Error connecting to MySQL: Access denied for user: ‘root@localhost’ (Using password: YES)

This is mainly caused due to the fact that the user root does not have enough privileges to access the mysql databases or the password set for the user root to connect mysql was changed.

1. Start mysql using mysqld_safe

#/usr/local/etc/rc.d/mysqld stop
#mysqld_safe –skip-grant-tables &

Note:
mysqld_safe is used to start mysql server by disabling certain feature that restrict a user to access mysql. The option –skip-grant-tables is used to neglect the permission grant to different users of mysql.

2. Enter mysql prompt by just typing “mysql” and do the following

>GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY ‘newpassword’ WITH GRANT OPTION;
>FLUSH PRIVILEGES;
>\q

3. Kill all mysql processes and start mysqld

#killall -9 mysqld_safe
#killall -9 mysqld
#/usr/local/etc/rc.d/mysqld start

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.