mysql5.7添加新用户

 添加新用户

# 允许本地 IP 访问 localhsot 127.0.0.1
create user 'test'@'localhost' identified by '123456';
# 允许外网 IP 访问
create user 'test'@'%' identified by '123456';
# 刷新权限
flush privileges;

为用户创建数据库

create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

为用户分配权限

# 授予用户通过外网 IP 对于该数据库的全部权限
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
# 授予用户在本地服务器对该数据库的全部权限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
# 刷新权限
flush privileges;
# mysql8
grant all privileges on `testdb`.* to 'test'@'localhost';
# 刷新权限
flush privileges;

 

 
 
posted @ 2020-10-21 12:18  pmm-cnblogs  阅读(215)  评论(0)    收藏  举报