mysql用户管理
来源:互联网 发布:个人房源采集软件 编辑:程序博客网 时间:2024/06/03 22:41
题外话: 最近使用zabbix。公司的zabbix监控的数据库掌握在别人手里,所以我就想能不能让他给我个权限,针对zabbix库下所有表具有select权限,而且还能导出信息。以前也碰到问题,都是碰到之后mysql help一下,现在有时间系统的总结下。
+++++++++++==8.7更新+++++++++++++++++++
题外话2:把zabbix库中的数据导出来,就先使用了视图,尝试下权限分配,尝试利用视图进行数据导出到csv格式的文件中。
+++++++++++++++++++++++++++++++++++++++++
来自mysql的help帮助信息。Name: 'CREATE USER'Description:Syntax:CREATE USER user_specification [, user_specification] ...user_specification: user [IDENTIFIED BY [PASSWORD] 'password']The CREATE USER statement creates new MySQL accounts. To use it, youmust have the global CREATE USER privilege or the INSERT privilege for the mysql database. #就是说你必须要有全局的create user 权限或者insert 权限。For each account, CREATE USER creates a new row inthe mysql.user table and assigns the account no privileges. An erroroccurs if the account already exists.#大家都知道的 mysql.user表。表中用户'user_name'@'host_name'和表中的另一条不能重合Each account name uses the format described inhttp://dev.mysql.com/doc/refman/5.1/en/account-names.html.
我去官网看了,这条链接直接跳转成现在的5.7的
https://dev.mysql.com/doc/refman/5.7/en/account-names.html
1)引号对于那些包含特殊字符的user_name是有必要的。host_name同理。
2)用户名(user_name)和host_name的长度限制
3)都是大小写敏感的。
太多了,自己可以去看看。
For example:CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';If you specify only the user name part of the account name, a host namepart of '%' is used.
默认的主机名
The user specification may indicate how the user should authenticatewhen connecting to the server:o To enable the user to connect with no password (which is insecure), include no IDENTIFIED BY clause:CREATE USER 'jeffrey'@'localhost';o To assign a password, use IDENTIFIED BY with the literal plaintext password value:CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';o To avoid specifying the plaintext password if you know its hash value (the value that PASSWORD() would return for the password), specify the hash value preceded by the keyword PASSWORD:CREATE USER 'jeffrey'@'localhost'IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';For additional information about setting passwords, seehttp://dev.mysql.com/doc/refman/5.1/en/assigning-passwords.html.URL: http://dev.mysql.com/doc/refman/5.1/en/create-user.html
所以简单也规范的创建用户是这样的
create user 'username'@'hostname' identified by 'passwd';
root(mysql的root)不给他赋予权限的话,他基本没了权限。只能登陆或者查看变量之类的,涉及到库,表等操作,是没有的。
除此之外的,比方说你创建了一个用户后,没有密码怎么搞?
使用set。help set password
Name: 'SET PASSWORD'Description:Syntax:SET PASSWORD [FOR user] = { PASSWORD('cleartext password') | OLD_PASSWORD('cleartext password') | 'encrypted password' }
给个例子就懂了:
set password for 'username'@'hostname' =password('passwd')如果你对自己修改的话: set password =password('passwd');就足够了。
关于使用grant给用户授权或者直接创建用户。
创建的用户没有权限,这时候就需要给他权限,否则一步难行。
Syntax:GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ... ON [object_type] priv_level TO user_specification [, user_specification] ... [REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}] [WITH with_option ...]object_type: TABLE | FUNCTION | PROCEDUREpriv_level: * | *.* | db_name.* | db_name.tbl_name | tbl_name | db_name.routine_nameuser_specification: user [IDENTIFIED BY [PASSWORD] 'password']ssl_option: SSL | X509 | CIPHER 'cipher' | ISSUER 'issuer' | SUBJECT 'subject'with_option: GRANT OPTION | MAX_QUERIES_PER_HOUR count | MAX_UPDATES_PER_HOUR count | MAX_CONNECTIONS_PER_HOUR count | MAX_USER_CONNECTIONS countThe GRANT statement grants privileges to MySQL user accounts. GRANTalso serves to specify other account characteristics such as use ofsecure connections and limits on access to server resources. To useGRANT, you must have the GRANT OPTION privilege, and you must have theprivileges that you are granting.
上面的一句话说的是:在授权是,你必须要有grant 权限,还有对一些库、表授权时,你必须对这些库、表有权限。就是说要种田,不仅要秧苗,还要有田。这里可以设置不同粒度的权限。可以参考如下博客http://www.cnblogs.com/nzbbody/p/4521267.html
Normally, a database administrator first uses CREATE USER to create anaccount, then GRANT to define its privileges and characteristics. Forexample:CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';GRANT ALL ON db1.* TO 'jeffrey'@'localhost';GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90;However, if an account named in a GRANT statement does not alreadyexist, GRANT may create it under the conditions described later in thediscussion of the NO_AUTO_CREATE_USER SQL mode.
就是说赋予用户权限时,没有该用户,他会给你创建出来。
下面给出别人博客总结的权限:
http://www.cnblogs.com/fslnet/p/3143344.html
现在举个例子授权给某个用户zabbix库中所有表的select权限。
grant select on zabbix.* to 'hexi'@'localhost' identified by '123456'或者已经创建了该用户。直接:grant select on zabbix.* to 'hexi'@'localhost'
当然直接往mysql.user表中进行数据的增删也可以创建用户,加完以后,flush privileges;
+++++++++++++++++++++++++++++++++++++++++++++
下面关于mysql权限的自身检查机制:
+++++++++++++++++++++++++++++++++++++++++++++
参考博客:
http://www.2cto.com/database/201310/252697.html
和权限有关的表出mysql.user表外,有如下:
如何控制客户访问?
下面讲讲MySQL服务器如何通过以上介绍的5张权限表控制客户访问。
1、用户连接时的检查
1)当用户连接时,MySQL服务器首先从user表里匹配host, user, password,匹配不到则拒绝该连接
2)接着检查user表的max_connections和max_user_connections,如果超过上限则拒绝连接
3)检查user表的SSL安全连接,如果有配置SSL,则需确认用户提供的证书是否合法
只有上面3个检查都通过后,服务器才建立连接,连接建立后,当用户执行SQL语句时,需要如下检查。
2、执行SQL语句时的检查
1)从user表里检查max_questions和max_updates,如果超过上限则拒绝执行SQL
下面几步是进行权限检查:
2)首先检查user表,看是否具有相应的全局性权限,如果有,则执行,没有则继续下一步检查
3)接着到db表,看是否具有数据库级别的权限,如果有,则执行,没有则继续下一步检查
4)最后到tables_priv, columns_priv, procs_priv表里查看是否具有相应对象的权限
从以上的过程我们可以知道,MySQL检查权限是一个比较复杂的过程,所以为了提高性能,MySQL的启动时就会把这5张权限表加载到内存。
有时候给的权限想要收回怎么办?给太多权某些人了,收回点权限。这时候revoke出场表演了。
查看用户权限:
show GRANTS [FOR user]
明天总结
- MySQL用户管理
- MySQL用户管理
- MYSQL用户帐号管理
- MySQL用户管理
- MySQL用户管理
- MySQL用户管理(1)
- MySQL用户管理(2)
- MYSQL用户帐号管理
- MySQL用户管理
- MySQL用户管理
- mysql用户管理
- mysql 用户管理
- MySQL的用户管理
- MySQL 用户管理
- mysql 用户的管理
- linux Mysql用户管理
- mysql 用户管理
- MySQL 用户管理 说明
- display的属性
- ssm多数据源的配置
- 超大型系统研发团队中的各类团队
- crf++ 安装
- js 根据已有File对象构造新的File对象
- mysql用户管理
- Tomcat7 registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver]
- 系统研发中的领导意志
- 6.1—排序—Merge Sorted Array
- leetcode 209.Minimum Size Subarray Sum 如何优化来减少时间
- 6.2—排序—Merge Two Sorted Lists
- synchronized
- 总师组的工作模式和方法
- 6.3—排序—Merge k Sorted Lists