文章詳情頁
MySQL用戶權限設置保護數據庫安全
瀏覽:107日期:2023-05-08 10:17:41
目錄
- 更改mysql密碼
- 創建用戶
- 給用戶所有權限
- 移除用戶所有權限
- 添加部分權限
- 移除部分權限
- 刪除用戶
- 權限解釋
- 案例
更改mysql密碼
-- 查詢用戶權限 show grants for "root"@"%"; update mysql.user set authentication_string=password("密碼") where user="root" and Host = "localhost"; flush privileges; -- 或者下面方式 alter user "test1"@"localhost" identified by "新密碼"; flush privileges;
創建用戶
-- 創建本地的 -- create user "test1"@"localhost" identified by "密碼"; -- 創建可以遠程訪問的 create user "wjl"@"%" identified by "wujialiang";
給用戶所有權限
-- grant all privileges on *.* to "wjl"@"localhost" with grant option; grant all privileges on *.* to "wjl"@"%" with grant option;
第一個表示通配數據庫,可指定新建用戶只可操作的數據庫
如:grant all privileges on 數據庫. to ‘test1’@‘localhost’;
第二個*表示通配表,可指定新建用戶只可操作的數據庫下的某個表
如:grant all privileges on 數據庫.指定表名 to ‘test1’@‘localhost’;
all privileges 可換成select,update,insert,delete,drop,create等操作 如:grant select,insert,update,delete on . to ‘test1’@‘localhost’;
移除用戶所有權限
-- revoke all privileges on *.* from "wjl"@"localhost"; revoke all privileges on *.* from "wjl"@"%";
添加部分權限
-- GRANT Select,Update,insert,delete ON *.* TO "用戶名"@"%"; GRANT select,update,insert,delete ON *.* TO "wjl"@"%";
移除部分權限
-- REVOKE select,insert ON 數據庫.* FROM wjl@"localhost" REVOKE select,insert ON 數據庫.* FROM wjl@"%"
刪除用戶
drop user "wjl"@"localhost";
權限解釋
案例
普通用戶權限
grant all privileges on *.* to "wjl"@"%" with grant option; REVOKE Shutdown,Process,Grant option,Drop ON *.* FROM wjl@"%"; flush privileges;
到此這篇關于MySQL用戶權限設置保護數據庫安全的文章就介紹到這了,更多相關MySQL用戶權限設置內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!
標簽:
MySQL
排行榜