
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表会显示多条授权记录
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)