mysql - 错误 1045 (28000) : Access denied for user 'root' @'%'

标签 mysql

我正在尝试运行

授予 * 上的所有权限。 * TO 'root'@'localhost';

从远程服务器到 localhost/phpmyadmin 但收到错误 1045 (28000): 用户 'root'@'%' 的访问被拒绝(使用密码:NO)。

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

如何解决这个问题?我在互联网上浏览了很多建议,但实际上无法弄清楚。

最佳答案

我认为,您忘记刷新权限

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

注意: 我已将 包含在 GRANT OPTION 中,因为正如文档所说:

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

编辑1:

根据评论,您似乎忘记了root密码。所以尝试像这样重置:

  1. 停止 MySQL 服务器。

    sudo/etc/init.d/mysql stop

  2. 无密码启动mysql

    sudo mysqld_safe --skip-grant-tables &

  3. root身份登录mysql:

    mysql -u root

  4. 将新密码设置为root

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

  5. 刷新权限。

    刷新权限;

  6. 最后正常重启mysql。

关于mysql - 错误 1045 (28000) : Access denied for user 'root' @'%' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36395296/

相关文章:

java - 如何使用 servlet 将数组列表中的数据填充到 html 中?

php - 表中没有插入数据

MySQL , JOIN , 当总数 = 1

PHP/mysql条件更新查询

mysql - 当特定列不为空时按优先级获取最大值

mysql - #1054 - 'name' 中的未知列 'field list'

php - 如何防止 PHP 中的 SQL 注入(inject)?

mysql - 一组以多对一的方式加入一排

mysql - 更好的做法是对所有行进行计数,还是将变量存储在表示行数的相关表中?

mysql 类型转换怪异