标签:
总的来说mysql的用户管理方法可以分为如下两种:
1、直接对mysql.user 表进行[insert | update | delete] + flush privileges 这种方式主要针对那种对mysql.user比较了解的DBA;
2、使用uml(user managerment language)语句 create user | drop user | grant | revoke | alter user 这种方式也是mysql推荐使用的;
下面的部分也主要对第二种方法进行说明:
1、mysql中的用户是什么?
我们和QQ做一个类比QQ的用户是一个人,腾讯公司用用QQ号来唯一标识这个人;与QQ不同是的mysql中的用户有两个维度一个是用户名、另一个就是它发起连接时
所在的主机
2、怎么来创建一个用户?
每一个mysql用户对应着mysql.user 表中的一行;如果你对mysql的用户管理了然于心那么你可以使用insert 一行到mysql.user表,来完成创建任务;这种方式本文不
会提到了,因为这样太累人了;先来看一下它的语法:
CREATE USER user_specification [, user_specification] ... user_specification: user [ identified_option ] auth_option: { IDENTIFIED BY ‘auth_string‘ | IDENTIFIED BY PASSWORD ‘hash_string‘ | IDENTIFIED WITH auth_plugin | IDENTIFIED WITH auth_plugin AS ‘hash_string‘ }
创建一个dumper用户它只能通过本机的回环网卡连接到mysql数据库
create user dumper@‘127.0.0.1‘ identified by ‘123@456‘;
3、grant 语句用来授权、权限是分层级的通常来说有实例级,数据库级,表级,列级;如果一用户有实例级别的select 权限,自然它也就有了数据库级,表级,列级的权限。
GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level TO user_specification [, user_specification] ... [REQUIRE {NONE | tsl_option [[AND] tsl_option] ...}] [WITH {GRANT OPTION | resource_option} ...] GRANT PROXY ON user_specification TO user_specification [, user_specification] ... [WITH GRANT OPTION] object_type: { TABLE | FUNCTION | PROCEDURE } priv_level: { * | *.* | db_name.* | db_name.tbl_name | tbl_name | db_name.routine_name } user_specification: user [ auth_option ] auth_option: { IDENTIFIED BY ‘auth_string‘ | IDENTIFIED BY PASSWORD ‘hash_string‘ | IDENTIFIED WITH auth_plugin | IDENTIFIED WITH auth_plugin AS ‘hash_string‘ } tsl_option: { SSL | X509 | CIPHER ‘cipher‘ | ISSUER ‘issuer‘ | SUBJECT ‘subject‘ } resource_option: { | MAX_QUERIES_PER_HOUR count | MAX_UPDATES_PER_HOUR count | MAX_CONNECTIONS_PER_HOUR count | MAX_USER_CONNECTIONS count }
授予一个用户所有权限:
这里有几个地方是要注意的
1、all 权限并不包涵grant option 权限。
2、all 权限也不包涵proxy 权限,并且proxy 的权限的层级是user级的
grant all on *.* to dumper@‘127.0.0.1‘; grant grant option on *.* to dumper@‘127.0.0.1‘; grant proxy on ‘root‘@‘localhost‘ to dumper@‘127.0.0.1‘;
标签:
原文地址:http://www.cnblogs.com/JiangLe/p/5876992.html