MySQL 5.7 修改密码 用户授权

2018/08/09 MySQL

1. 修改密码

mysql -u root -p

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

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

2. 删除用户

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;

3. 为用户授权

授权格式: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; #刷新系统权限表

4. 显示当前用户信息

select user();

Search

    Table of Contents