MySQL grant 语法
生活随笔
收集整理的這篇文章主要介紹了
MySQL grant 语法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:grant 權限 on 數據庫對象 to 用戶 - 這才是真的阿呆云飛 - 博客園
基本語法:
grant 權限 on 數據庫對象 to 用戶?identified by 密碼
用戶一般格式是:用戶名@IP?
說明:IP有時候會寫%。%是個通配符,如果Host=192.168.1.%,那么就表示只要是IP地址前綴為“192.168.1.”的客戶端都可以連接。如果Host=%,表示所有IP都有連接權限
當不加@選項時,效果與加@'%'是一樣的,'%'從名義上包括任何主機,(%必須加上引號,不然與@放在一起可能不會被辨認出。)不過有些時候(有些版本)'%'不包括localhost,要單獨對@'localhost'進行賦值
一、基本權限設置
--? 賦予用戶common_user在所有IP上擁有testdb數據庫中所有表的增/刪/查/改的權限grant select(insert 或update或delete ) on testdb.*? ?to common_user@’%’;-- 一次性賦予增刪查改的所有權限grant select, insert, update, delete on testdb.* to common_user@’%’;-- grant 創建、修改、刪除、操作索引 MySQL 數據表結構權限。grant create/alter/drop/index on testdb.* to user@’192.168.0.%’;-- grant 操作 MySQL 外鍵權限。grant references on testdb.* to user@’192.168.0.%’;-- grant 操作 MySQL 臨時表權限。grant create temporary tables on testdb.* to user@’192.168.0.%’;-- grant 操作 MySQL 視圖、查看視圖源代碼 權限。grant create view on testdb.* to user@’192.168.0.%’;grant show view on testdb.* to user@’192.168.0.%’;二、高級權限、細分權限
1、所有數據庫所有表:*.* -- 授權用戶 dba 所有數據庫所有表的所有權限 grant all (privileges) on *.* to dba@’localhost’;2、一個數據庫所有表:數據庫名(.*) -- 授權用戶 dba 針對 testdb 數據庫所有表的所有權限 grant all (privileges) on testdb to dba@’localhost’;3、一個數據庫一個數據表:庫.表 grant select, insert, update, delete on testdb.orders to dba@localhost;-- 給一個用戶授權多張表時,可以多次執行以上語句。例如:grant select on smp.users to mo_user@’%’ identified by ‘123345′;grant select on smp.mo_sms to mo_user@’%’ identified by ‘123345′;4、 grant 作用在表中的列上: grant select(id, se, rank) on testdb.apache_log to dba@localhost;?三、查詢權限
-- 查看當前用戶(自己)權限: show grants;-- 查看其他 MySQL 用戶權限: show grants for zhangkh@'192.168.1.10';四、回收權限?
-- 把grant 換成revoke to 換成 from -- grant, revoke 用戶權限后,該用戶只有重新連接 MySQL 數據庫,權限才能生效。grant all on *.* to dba@localhost; revoke all on *.* from dba@localhost;五、授予權限
-- 想讓授權的用戶,也可以將這些權限 grant 給其他用戶,需要選項 “grant option“ grant select on testdb.* to dba@localhost with grant option;-- 使myuser使用mypassword從任何主機連接到mysql服務器 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; FLUSH PRIVILEGES; -- 允許用戶myuser從ip為192.168.1.6的主機連接到mysql服務器,并使用mypassword作為密碼 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; FLUSH PRIVILEGES; -- 允許用戶myuser從ip為192.168.1.6的主機連接到mysql服務器的dk數據庫,并使用mypassword作為密碼 GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; FLUSH PRIVILEGES;?
總結
以上是生活随笔為你收集整理的MySQL grant 语法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 毕业2年,我的工作小结
- 下一篇: C语言必须写main函数?最简单的 He