mysql用户管理

1 用户创建

创建user1用户,只能在localhost这个服务器登录mysql服务器,密码123

create user 'user1'@'localhost' identified by '123';

创建user2用户,可以在任意服务器登录mysql服务器,密码123

create user 'user2'@'%' identified by '123';

创建的用户在mysql 数据库 user表中

2 用户授权与撤销

给user1用户分配对test数据库操作权限:创建表,修改表,插入更新查询

grant create,alter,insert,update,select on test.* to 'user1'@'localhost';

user2分配所有权限

grant all on *.* to 'user2'@'%';

撤销user1用户对test数据库所有权限

revoke all on test.* from 'user1'@'localhost';

查看权限、

show grants for 'user2'@'%';

删除用户

drop user 'user1'@'localhost';

修改管理员root密码为123

mysqladmin -uroot -p password 123

修改普通用户密码

set password for 'user1'@'localhost'=password('123456');

Navicat无法连接数据库的解决办法

打开【win+r】输入CMD进入命令行界面,然后输入

alter user 'root'@'localhost' identified by '密码' password expire never;

alter user 'root'@'localhost' identified with mysql_native_password by '密码';

flush privileges;

记得将密码替换为mysql 的密码。

原文地址:https://www.cnblogs.com/hellosiyu/p/12501998.html