mysql如何让一个用户同时管理多个数据库

mysql如何让一个用户同时管理多个数据库,第1张

mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail

mysql -u root -p

password

use mysql

insert into user(host,user,password) values('localhost','hail',password('hail'))

flush privileges

create database haildb

grant all privileges on haildb.* to hail@localhost identified by 'hail'

flush privileges

如果想指定部分权限给用户

grant select,update on haildb.* to hail@localhost identified by 'hail'

flush privileges

删除用户

delete from user where user='hail' and host='localhost'

flush privileges

删除用户数据库

drop database haildb

修改指定用户密码

update user set password=password('new_password') where user='hail' and host='localhost'

flush privileges

增加新用户

格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"

如,增加一个用户user1密码为password1,让其可以在本机上登录, 并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入mysql,然后键入以下命令:

grant select,insert,update,delete on *.* touser1@localhost Identified by "password1"

如果希望该用户能够在任何机器上登陆mysql,则将localhost改为"%"。

如果你不想user1有密码,可以再打一个命令将密码去掉。

all代表所有权限;

grant select,insert,update,delete on mydb.*to user1@localhost identified by ""

例:

grant all on dbname.* to user@”%”identified by "password"

grant all on dbname.* to user@”%” identifiedby "password"

GRANT ALL PRIVILEGES ON `mydb`.* TO 'root'@'192.168.%.%' identified by 'mypwd' WITH GRANT OPTION

GRANT ALL PRIVILEGES ON `mydb`.* TO 'root'@'10.111.1.80' identified by 'mypwd' WITH GRANT OPTION

GRANT ALL PRIVILEGES ON `mydb`.* TO 'root'@'172.%.%.%' identified by 'mypwd' WITH GRANT OPTION

FLUSH PRIVILEGES

不可以用逗号分隔,只能多次授权。

数据库mysql下user表会显示多条授权记录


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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存