Access denied for user ‘root’@’%’ to database

Posted: December 8, 2008 in Linux

Access denied for user ‘root’@’%’ to database

I have created a new database, i can’t able to access my database from my PHP application running in another system.  I got the following error in the browser.

ERROR:

Access denied for user ‘root’@’%’ to database

How to solve?

I have changed the privilage for the database by giving the following commands.

$mysql –u root

#GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, DROP, REFERENCES, LOCK TABLES ON <databasename>.* TO <username>@localhost;

# GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, DROP, REFERENCES, LOCK TABLES ON <database>.* TO xxx@’192.168.1.%‘;


#GRANT ALL PRIVILEGES ON *.* TO ‘xxx’@’%’ IDENTIFIED BY PASSWORD ” WITH GRANT OPTION;

#FLUSH PRIVILEGES;

After that restart you MySQL Server using

#service mysqld restart

Now you can able to access the database.

Hope this may help you.

Thank you                                                                                                                                         Bharath M

Comments
  1. […] the original: Access denied for user ‘root’@’%’ to database Related ArticlesBookmarksTags Google Web API; Access to Google’s Engine [BN] I had been […]

  2. Only-life says:

    A very good message and it is useful to me. Thank you for your good article.

  3. Diego Ramos says:

    This helped me a lot! Thank you so much!

  4. tbdaugaard says:

    Neither of these solutions worked for me, however since I have root access to the machine, I was able to do this:

    # /etc/init.d/msql stop
    # mysqld –datadir=/var/lib/mysql –skip-grant-tables &
    # mysql
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 5.0.51a-24+lenny5 (Debian)

    mysql> USE mysql;
    mysql> UPDATE user SET Grant_priv = ‘Y’ WHERE user = ‘root’;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0
    mysql>
    # /etc/init.d/mysql restart

    My problem was that my ‘root’ user had lost the GRANT privilege and there is no way of getting that back unless you run mysqld with –skip-gran-tables (which efffectively bypasses *any and all* security on the MySQL server instance)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s