MySQL用户创建及权限管理

创建用户admin,只能在本地登陆,密码123456

#CREATE USER 'admin'@'localhost' IDENTIFIED BY '123456';


可以查看创建账户状态

#show create user admin@'localhost';


赋予权限   all所有权限增删改查  第一个*是数据库级授权 ,第二个*是表级授权,只能本地登陆
#grant all privileges on *.* to 'admin'@'localhost';


可以查看用户赋予的特权

#show grants for 'admin'@'localhost';


查询当前登陆用户名

#select current_user();


赋予远程连接权限blog数据库中blog用户
#grant all privileges on blog.* to 'blog'@'%';

取消远程连接权限blog数据库中blog用户
#revoke all on blog.* from 'blog'@'%'; 

创建一个用户admin2只能在192.168.31段网络远程访问密码[Mima123];

#create user 'admin2'@'192.168.31.%' identified by '[Mima123]';


赋予权限并创建用户

#grant all on blog.* to 'blog2'@'192.168.31.%' identified by '[Mima123]';


privileges权限有

        select,(常用)
insert,(常用)
update,(常用)
delete,(常用)
create,(常用)
drop,  (常用)
references,
index,
alter,
create temporary tables,
lock tables,
execute,
create view,
show view,
create routine,
alter routine,
event,
trigger






	
	Example  数据库创建、用户创建赋予权限操作
	
	#create database test_example;                                                                  	#创建数据库
	#use test_example;											#进入数据库
	#create table t1(id int, user varchar(12),pwd varchar(12));						#创建表t1
	#create table t2(id int, name varchar(12),phone varchar(12));						#创建表t2
	#desc t1;   desc t2;    										#查看表信息
	
	####grant all on test_example.* to 'test1'@'192.168.31.179' identified by '[Mima123]';			#创建用户test1密码[Mima123],并赋予在192.168.31.179远程连接test_example数据库所有表的权限
	
	#CREATE USER 'test1'@'192.168.31.179' IDENTIFIED BY '[Mima123]';                                        #用这个比较好
	
	#select user,host from mysql.user;
	#show grants for 'test1'@'192.168.31.179'; 								#显示用户权限			
	#revoke all on test_example.* from 'test1'@'192.168.31.179';						#移除权限
	
	赋予test1在192.168.31.179主机连接数据库test_example中t1表select、update权限,但在插入的时候只能插入id、user字段(插入完成后可以更新pwd字段)
	#grant select,insert(id,user),update on test_example.t1 to 'test1'@'192.168.31.179';
	赋予test1在192.168.31.179主机连接数据库test_example中t2表select、update权限,但在插入的时候只能插入id、phone字段(插入完成后可以更新name字段)
	#grant select,insert(id,phone),update,delete on test_example.t2 to 'test1'@'192.168.31.179';	
	
	
	Example end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值