MySql全套攻略——添加新用户、为用户创建数据库和给用户分配权限

时间:2022-01-11 08:49:07
1.添加新用户
只允许本地IP访问
create user 'test'@'localhost' identified by '123456';

允许外网IP访问

create user 'test'@'%' identified by '123456';
刷新授权
flush privileges;

2.为用户创建数据库

create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;  

3.为用户分配权限

授予用户通过外网IP操作该数据库的所有去权限

grant all privileges on `testdb`.* to 'test'&'%' identified by '123456';

授予用户通过外网IP操作所有数据库的权限

grant all privileges on *.* to 'test'&'%' identified by '123456';

刷新授权

flush privileges;