简体   繁体   中英

ERROR 1045 (28000): Access denied for user 'root'@'%'

I am trying to run

GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost';

from a remote server to localhost/phpmyadmin but getting ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: NO).

mysql> show grants;
+----------------------------------+
| Grants for root@%                |
+----------------------------------+
| GRANT USAGE ON *.* TO 'root'@'%' |
+----------------------------------+

How can I resolve this problem? I have gone through a lot of suggestions over internet but can't actually figure out.

I think, you forgot to flush privileges .

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' with GRANT OPTION;
mysql> FLUSH PRIVILEGES;

Note: I have included with GRANT OPTION because as doc says:

The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.

Edit 1:

Depending on comments, seems like you have forgotten the root password. So try to reset like this:

  1. Stop the MySQL Server.

    sudo /etc/init.d/mysql stop

  2. Start the mysql without password

    sudo mysqld_safe --skip-grant-tables &

  3. Login to mysql as root :

    mysql -u root

  4. Set new password to root

    UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

  5. Flush privileges.

    FLUSH PRIVILEGES;

  6. Finally, restart mysql normally.

If you have root credential , then Set the privileges like mentioned below.

grant all privileges on db.* to user@'%' identified by 'pass';

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM