【问题标题】:Mysql root access deniedMysql root 访问被拒绝
【发布时间】:2013-11-25 07:31:06
【问题描述】:

我似乎忘记了在终端 (mac) 中以 root 用户身份登录 MySql 的密码。我在 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html 查阅了 mysql 文档,但这似乎对我不起作用。接下来我还能做什么?

user$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

这是我当前可用的数据库 w。 MySql 数据库似乎没有出现在那里。这是为什么呢?

user$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.13 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+

【问题讨论】:

    标签: mysql database unix terminal user-permissions


    【解决方案1】:

    我个人从来没有能够让 ini 或文本文件方法在重置时发送其他命令。

    C.5.4.1.3 下的通用指令。重置 Root 密码:来自该超链接的通用说明通常是我发现的工作方式。

    要更改您的 root 密码:

    1. 如果 mysqld 当前正在运行,请停止它。
    2. 使用--skip-grant-tables 命令行选项在“安全模式”中启动mysqld。 (注意:建议尽可能使用--skip-networking 选项,以避免在您执行此操作时向网络/ Internet 的其余部分开放对您的数据库服务器的访问!!)

      这将启动 mysql 守护进程。

    3. 打开您喜欢的 mysql 客户端并以 root 身份登录,无需密码或在终端输入 mysql -u root。您不需要密码,因为授权表已被跳过。

      您现在应该能够登录到 mysql 服务器并看到 MOTD / 欢迎消息。

    4. 运行这些 SQL 命令(注意:记住结尾的分号!)

      use mysql;
      
      update user SET Password=PASSWORD('MyNewPass') WHERE User='root';
      FLUSH PRIVILEGES;
      
    5. 退出mysql客户端

    6. 停止mysqld 守护进程 - 重要!如果您不停止守护进程,那么数据库服务器将继续以开放的权限运行!!

    7. 正常情况下重启mysqld守护进程。

    回答你的问题:

    这是我当前可用的数据库 w。 MySql 数据库似乎没有出现在那里。这是为什么呢?

    除非您拥有全局 SHOW DATABASES 权限,否则您只能看到您拥有某种权限的那些数据库。

    见:MySQL SHOW DATABASES Documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-30
      • 2020-01-08
      • 2013-08-22
      • 1970-01-01
      • 2021-06-27
      • 2011-11-24
      • 2021-06-26
      • 2016-07-11
      相关资源
      最近更新 更多