MySQL: Access denied for user

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

Situation:
If we try to connect mysql, sometimes we get an error as  given below.
          

  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.

Solution:

Follow the steps below to fix this error.

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


4. Verify the result

# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g
Your MySQL connection id is XXXXX to server version: 4.1.11-standard

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>


 

Both comments and pings are currently closed.

Comments are closed.