【问题标题】:mysql showing different number of databasesmysql显示不同数量的数据库
【发布时间】:2014-07-09 08:07:29
【问题描述】:

这是来自我在 mac 中的终端。

130-229-0-129-dhcp:~ suyeshamatya$ mysql


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)

mysql> quit
Bye
130-229-0-129-dhcp:~ suyeshamatya$ mysql -u root -p
Enter password: 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lportal            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

谁能解释一下为什么mysql在没有任何用户名/密码连接和使用root连接时显示不同数量的数据库用户名/密码?

更新:

无需用户名/密码即可连接

mysql> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)

用root用户名/密码连接

mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '********************' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

【问题讨论】:

    标签: mysql terminal


    【解决方案1】:

    授予 USAGE 意味着根据Manual,该用户没有权限。因此,当您在没有 用户名密码 的情况下登录时。它将显示默认的 mysql 架构。如果您想使用以下查询:

    select User from mysql.user;
    

    它会抛出类似的错误

    SELECT command denied to user ''@'localhost' for table 'user';
    

    这意味着您没有默认数据库查看用户详细信息的权限。

    如果您使用用户名和密码登录,那么该用户创建的所有数据库都会显示给您。

    【讨论】:

      【解决方案2】:

      我不确定,但我认为“未知用户”没有权限查看其他数据库。请在 mysql 数据库中检查。

      【讨论】:

        猜你喜欢
        • 2016-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-21
        • 2018-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多