作者:佚名 时间:2025-04-17 18:49:19 阅读:(65)
在使用MySQL数据库时,创建新用户后通常需要为其分配相应的权限,以便能够访问或操作特定的数据库。MySQL提供了GRANT命令来实现用户授权,可以指定用户对某个数据库或表的查询、插入、更新等权限。接下来将为大家介绍MySQL为用户授权的具体方法和使用示例,方便灵活管理数据库权限。
grant 权限 ON 数据库.* to 用户名@登录主机 identified by "密码";
mysql>insert into mysql.user(Host,User,Password) values('localhost','yundreams',password('123456')); mysql>flush privileges;//刷新系统权限表
create database yundreams;
mysql>grant all privileges ON yundreams.* to 'yundreams'@'localhost' identified by '123456'; mysql>flush privileges;//刷新系统权限表
mysql>grant select,update on yundreams.* to yundreams@localhost identified by '123456'; mysql>flush privileges; //刷新系统权限表
mysql>grant select,delete,update,create,drop on *.* to yundreams@"%" identified by "123456"; //yundreams用户对所有数据库都有select,delete,update,create,drop 权限。 //@"%" 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。) //对localhost授权:加上一句grant all privileges on yundreams.* to yundreams@localhost identified by '123456';即可。
以上就是云梦编程为大家介绍的Mysql为用户授权的方法,希望对大家有所帮助,了解更多相关文章请关注云梦编程网!