mysql5.7 用户和权限管理(Linux系统下)

 

1. 查看用户
	use mysql;
	select user,host,authentication_string from user;

		mysql> use mysql;
		Reading table information for completion of table and column names
		You can turn off this feature to get a quicker startup with -A

		Database changed
		mysql> select user,host,authentication_string from user;
		+---------------+-----------+-------------------------------------------+
		| user          | host      | authentication_string                     |
		+---------------+-----------+-------------------------------------------+
		| root          | localhost | *49D7A8D9455A990A12052F5C72D569B9EAEC155A |
		| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
		| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
		| myuser        | %         | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
		| root          | %         | *49D7A8D9455A990A12052F5C72D569B9EAEC155A |
		+---------------+-----------+-------------------------------------------+
		5 rows in set (0.00 sec)

2. 创建用户
	语法:create user 用户名@主机 identified by 密码;
	例如:
		create user test@localhost identified by '123456';


		mysql> create user test@localhost identified by '123456';
		Query OK, 0 rows affected (0.00 sec)

		mysql> select user,host,authentication_string from user;
		+---------------+-----------+-------------------------------------------+
		| user          | host      | authentication_string                     |
		+---------------+-----------+-------------------------------------------+
		| root          | localhost | *49D7A8D9455A990A12052F5C72D569B9EAEC155A |
		| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
		| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
		| myuser        | %         | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
		| root          | %         | *49D7A8D9455A990A12052F5C72D569B9EAEC155A |
		| test          | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
		+---------------+-----------+-------------------------------------------+
		6 rows in set (0.01 sec)

3.用户授权
	语法:grant 权限列表 on 库名.表名 to 用户@主机 identified by '密码';
	例如:grant select,delete,update,create,drop on . to test@"192.168.%.%" identified by "123456"; 
		# "%" 表示对所有非本地主机授权,不包括localhos
		# *.*:所有库上的所有表; 
		# 192.168.%.%:192.168内的所有Ip;
		# 123456:密码
	刷新权限:flush privileges;


4. 查看用户权限
	语法:show grants for 用户@主机;
	例如:show grants for test@localhost;

		mysql> show grants for test@localhost;
		+------------------------------------------+
		| Grants for test@localhost                |
		+------------------------------------------+
		| GRANT USAGE ON *.* TO 'test'@'localhost' |
		+------------------------------------------+
		1 row in set (0.00 sec)

5. 回收权限
	回收权限有两种方法:删除用户和revoke

	回收语法:revoke 权限 on 库名.表名 from 用户@主机;
	例如:revoke all on *.* from test@localhost;
	revoke insert,select on *.* from test@localhost;

6. 删除账户及权限
	语法:drop user 用户名@主机;
	例如:drop user 'test'@localhost;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值