我在mysql命令行
中使用此命令创建了一个用户GRANT ALL PRIVILEGES ON `db_name.*` to 'db_name_admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
我用
连接数据库mysql -u db_name_admin -p -h localhost
检查我是否已连接
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_name |
+--------------------+
2 rows in set (0.00 sec)
然后我改为使用正确的数据库
use db_name
但是当我做的时候
show tables
我得到了
empty set (0.00 sec)
当我使用root帐户登录时,我可以看到db_name中的所有表和记录。 所以我猜我的GRANT查询有问题,但我无法弄清楚是什么。
当我检查TABLE_PRIVILEGES时,我看到了
+-----------------------------+---------------+--------------+--------------+----------------+--------------+
| GRANTEE | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | PRIVILEGE_TYPE | IS_GRANTABLE |
+-----------------------------+---------------+--------------+--------------+----------------+--------------+
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | SELECT | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | INSERT | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | UPDATE | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | DELETE | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | CREATE | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | DROP | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | REFERENCES | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | INDEX | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | ALTER | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | CREATE VIEW | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | SHOW VIEW | YES |
| 'db_name_admin'@'localhost' | def | db_name | db_name.* | TRIGGER | YES |
+-----------------------------+---------------+--------------+--------------+----------------+--------------+
我的数据库名称使用 - 符号命令应为
GRANT ALL PRIVILEGES ON `db-name`.* to 'db_name_admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
答案 0 :(得分:2)
执行:GRANT ALL PRIVILEGES ON db_name.* ...
没有反引号
反引号“冻结”您在那里键入的内容,因此您只获得名为“db_name。*”的表的权限。