mysql 5.7 用户操作

mysql> use mysql;

mysql> selecthost,user from user;

 

查看结果是不是root用户仅允许本地(localhost)登录,下面这个截图就是这种情况.

是的话,就要修改它的host为%,表示任意IP地址都可以登录.

\

 

mysql> update user set host = '%' where user = 'root';

执行完后可能提示error.再mysql> select host,user from user;查看下吧.

root对应的host成了%,表示可以任意IP地址登录了.

\

 

mysql> flush privileges;

把缓存flush掉.在使用update语句修改用户记录后,需要FLUSH语句告诉服务器重载授权表.


一、修改密码

mysql -u root -p 

update mysql.user set authentication_string = password (“新密码”) where User=”test” and Host=”localhost”; 

flush privileges;

mysql5.7以后mysql.user表中没有了password字段,而是使用authentication_string来代替。

二、删除用户

mysql -u root -p 

Delete FROM mysql.user Where User="用户名" and Host=”localhost”; 

flush privileges; 

创建用户

命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password';

删除账户及权限:

drop user 用户名@’%’;

drop user 用户名@ localhost;

三、为用户授权

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

eg: grant all privileges on *.* to 'root'@'192.168.218.128' identified by 'hello' with grant option;

flush privileges; //要刷新权限


授权test用户拥有testDB数据库的所有权限:

grant all privileges on testDB.* to “test”@”localhost” identified by “1234”; 
flush privileges; #刷新系统权限表


指定部分权限给用户:

grant select,update on testDB.* to “test”@”localhost” identified by “1234”; 
flush privileges; #刷新系统权限表

四、显示当前用户信息

select user();


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值