无法在 mysql 中看到授予的数据库

问题描述

如果我创建用户并授予它对某个数据库的所有权限,但稍后使用该用户登录时,我看不到授予的数据库

MysqL> show databases;
+--------------------+
| Database           |
+--------------------+
| exmaple_database   |
| information_schema |
| loginsystem        |
| MysqL              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

MysqL> create user 'example_user'@'localhost' identified with MysqL_native_password by 'password';
Query OK,0 rows affected (0.01 sec)

MysqL> select user,host from MysqL.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| example_user     | localhost |
| MysqL.infoschema | localhost |
| MysqL.session    | localhost |
| MysqL.sys        | localhost |
| root             | localhost |
| www_data         | localhost |
+------------------+-----------+
7 rows in set (0.00 sec)

MysqL> grant all on example_database.* to 'example_user'@'localhost';
Query OK,0 rows affected (0.06 sec)

MysqL> flush privileges;
Query OK,0 rows affected (0.01 sec)

MysqL> show grants for 'example_user'@'localhost';
+----------------------------------------------------------------------------+
| Grants for example_user@localhost                                          |
+----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `example_user`@`localhost`                           |
| GRANT ALL PRIVILEGES ON `example_database`.* TO `example_user`@`localhost` |
+----------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MysqL> exit
Bye
$ MysqL -u example_user -p
Enter password: 
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 18
Server version: 8.0.23-0ubuntu0.20.10.1 (Ubuntu)

copyright (c) 2000,2021,Oracle and/or its affiliates.

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 |
+--------------------+
1 row in set (0.01 sec)

MysqL> 

从上面可以看出,用户被授予 example_database,但是当使用 example_user 登录并被授予 show databases; 时,example_database 没有显示。有什么理由吗? https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04 指南(我遵循的指南)建议在创建用户时使用 MysqL_native_password,以便从 PHP 与该用户建立联系。但我不认为这个选项与这个问题有关。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)