创建用户
1.登录mysql
mysql -uroot -p
2.创建本地用户(2.3选其一)
#use mysql; //选择mysql数据库
#create user 'wen'@'localhost' identified by '123456'; //创建本地用户
#flush privileges; //刷新MySQL的系统权限相关表,使添加用户操作生效,以免会出现拒绝访问
3.创建远程用户
#create user 'wen'@'192.168.122.12' identified by 'qing'; //从192.168.122.12登陆的用户
#create user 'wen'@'%' identified by '123456'; // 从任意ip登陆的用户
#create user 'wen' identified by '123456'; //不做指定默认为'%'
4.删除用户
# use mysql;
# delete from user where user='wen' and host='%' ;
#flush privileges;
为用户创建数据库
1.创建数据库
create database qing DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
2.删除数据库
drop database 数据库名;
为新用户分配权限
1.分配权限
#grant select,delete,update,insert on qing.* to 'wen'@'localhost' identified by '123456';
//赋予部分权限,其中的wen.*表示对以wen所有文件操作。
#flush privileges; //刷新权限
#grant all privileges on qing.* to 'wen'@'%' identified by '123456'; //赋予所有权限
#flush privileges; //刷新权限
2.撤销权限
#revoke updata on qing.* from 'wen'@'%'; //撤销updataq权限
#revoke all on qing.* from 'wen'@'%'; //撤销所有权限