基于mysql5.7
为用户创建数据库
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
推荐快速用户并远程访问
GRANT ALL PRIVILEGES ON test.* TO 'test'@'%' IDENTIFIED BY 'test' WITH GRANT OPTION;
#刷新
flush privileges;
以下都是在root用户下操作
创建用户
即将user表的localhost改为%
CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
查询用户
select user,host from mysql.user;
删除用户
判断有没有开启远程访问,本地访问使用上面
远程访问使用下面的删除
DROP USER 'test'@'localhost';
或
DROP USER 'test'@'%';
授权远程访问
即将host字段localhost改为%
update mysql.user set host = '%' where user = 'test';
flush privileges;
暴力,给了所有库所有权限,并远程访问
不推荐,
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'test' WITH GRANT OPTION;
flush privileges;
查看权限
show grants for test;
授权
#授权 所有权限
GRANT privileges ON 数据库名.表名 TO '用户名'@'host'
#授权 部分权限
grant select,insert,update,delete on gushici.* to 用户名@"%" identified by "密码";
修改密码
#修改root密码
set password = password('密码');
flush privileges;
#修改普通用户密码
set password for 用户名@localhost = password('密码');
flush privileges;