mysql授權
阿新 • • 發佈:2018-07-27
set show mil gif enum 方便 技術分享 本機 ice 通過grant 命令創建用戶並授權:
1,創建mysql用及授予權限:
在mysql中輸入help grant 會出現下面信息:
CREATE USER ‘jeffrey‘@‘localhost‘ IDENTIFIED BY ‘mypass‘; GRANT ALL ON db1.* TO ‘jeffrey‘@‘localhost‘; GRANT SELECT ON db2.invoice TO ‘jeffrey‘@‘localhost‘; GRANT USAGE ON *.* TO ‘jeffrey‘@‘localhost‘ WITH MAX_QUERIES_PER_HOUR 90;View Code
通過grant 命令創建用戶並授權:
mysql> grant all privileges on wordpress.* to ‘userdb‘@‘localhost‘ identified by ‘admin‘; Query OK, 0 rows affected (0.00 sec)
生產環境針對主庫(寫入主讀為輔)用戶的授權;
普通環境:
本機:lnmp,lamp環境數據庫授權
grant all privileges ON blog.* to blog@localhost identified by ‘123456’
應用服務器和數據庫服務器不在一個主機上授權;
grant all privileges ON blog.* to blog@10.0.0.% identified by ‘123’
嚴格的授權:重視安全,忽略了方便;
grant select,insert,update,delete ON blog.* to blog@10.0.0.% identified by ‘123’
生產環境從庫(只讀)用戶的授權;
grant select ON blog.* to blog@10.0.0.% identified by ‘123’
查看授權用戶oldboy的具體的授權權限
show grants for ‘oldboy’@’localhost’;
第一種:授權用戶
grant all on test.* to oldboy@127.0.0.% identified by ‘oldboy123’
show grants for oldboy@’127.0.0.%’; 查看授權用戶
+-------------------------------------------------------------------------------------------------------------+
| Grants for root@127.0.0.1|
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘root‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘ |
| GRANT ALL PRIVILEGES ON `test`.* TO ‘root‘@‘127.0.0.1‘ |
+-------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
■ 第二種:授權方法
create user bbs@‘172.16.1.1/255.255.255.0‘ identified by ‘123456‘;
先授權可以登錄的
mysql> show grants for bbs@‘172.16.1.1/255.255.255.0‘;
mysql> grant select on wordpress.* to bbs@‘172.16.1.1/255.255.255.0‘;
授權局域網主機連接遠程數據庫
a.一條命令百分號匹配法
grant all on *.* to‘test@10.0.0.%’identified by ‘test123’;
b、一條命令子網掩碼配置法
grant all on *.* to test@’10.0.0.0/255.255.255.0’ identified by ‘test123’;
c、兩條命令實現
先創建用戶並設置密碼;
create user test@’10.0.0.%’ identified by ‘test123’;
再對用戶授權指定權限和管理庫表
grant all on *.* to test@10.0.0.0/255.255.255.0
最後記得上述每條grant命令都要刷新權限
flush privilege
數據庫遠程登錄
mysql -uwordpress -poldboy123 -h 172.16.1.51 -P3306
-h指定IP地址,-P指定服務端口號
創建類似於root系列的管理員用戶,可以創建下級用戶的用戶
grant all privileges on *.* to root@‘127.0.0.1‘ identified by ‘oldboy123‘ with grant option;
只需要在最後輸入with grant option
回收用戶權限
REVOKE INSERT ON *.* FROM ‘jeffrey‘@‘localhost‘;
mysql授權