微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法在 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 举报,一经查实,本站将立刻删除。