MySQL用户权限设置保护数据库安全
目录 更改mysql密码 创建用户 给用户所有权限 移除用户所有权限 添加部分权限 移除部分权限 删除用户 权限解释 案例 更改mysql密码 -- 查询用户权限show grants for 'root'@'%';update mysql.user
目录更改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用户权限设置内容请搜索每日运维以前的文章或继续浏览下面的相关文章希望大家以后多多支持每日运维!