如何修改mysql数据库的访问权限

如何修改mysql数据库的访问权限,第1张

你的mysql数据库里面有一个数据库,名字教做mysql,里面有个表,名字叫做user,你看一下这个表的结构和现有数据,你就知道应该怎么做了,比如你可以添加一条数据,host为你指定的ip,user可以是%,password就不管了,后面设置相应的权限(可以全部都是y),这样那个机器无论用什么用户和密码都可以连接数据库,而拥有你指定的权限。

耐心点吧,我相信你一看就明白。

1,要授予的权限

2,被授予访问权限的数据库或表

3,用户名

grant和revoke可以在几个层次上控制访问权限

1,整个服务器,使用 grant ALL 和revoke ALL

2,整个数据库,使用on database.*

3,特点表,使用on database.table

4,特定的列

5,特定的存储过程

1、创建新用户

通过root用户登录之后创建

>>grant all privileges on *.* to testuser@localhost identified by "123456" //创建新用户,用户名为testuser,密码为123456 ;

>>grant all privileges on *.* to testuser@localhost identified by "123456" //设置用户testuser,可以在本地访问mysql

>>grant all privileges on *.* to testuser@"%" identified by "123456"  //设置用户testuser,可以在远程访问mysql

>>flush privileges //mysql 新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效

2、设置用户访问数据库权限

>>grant all privileges on test_db.* to testuser@localhost identified by "123456" //设置用户testuser,只能访问数据库test_db,其他数据库均不能访问 ;

>>grant all privileges on *.* to testuser@localhost identified by "123456" //设置用户testuser,可以访问mysql上的所有数据库 ;

>>grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" //设置用户testuser,只能访问数据库test_db的表user_infor,数据库中的其他表均不能访问 ;

3、设置用户 *** 作权限

>>grant all privileges on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION //设置用户testuser,拥有所有的 *** 作权限,也就是管理员 ;

>>grant select on *.* to testuser@localhost identified by "123456" WITH GRANT OPTION //设置用户testuser,只拥有【查询】 *** 作权限 ;

>>grant select,insert on *.* to testuser@localhost identified by "123456" //设置用户testuser,只拥有【查询\插入】 *** 作权限 ;

>>grant select,insert,update,delete on *.* to testuser@localhost identified by "123456" //设置用户testuser,只拥有【查询\插入】 *** 作权限 ;

>>REVOKE select,insert ON what FROM testuser//取消用户testuser的【查询\插入】 *** 作权限 ;


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10071218.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存