1
我創建了這個命令的用戶在mysql命令行創建帶命令行的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
檢查,看是否我connectd
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;
感謝您編輯我的文章。 如何編輯代碼塊以顯示代碼? 我一次只能管理1行。 – anatak