mysql 授权命令

MySQL清空数据库的操作:truncate table tablename;

MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户  
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。

1 grant select on testdb.* to [email protected]‘%‘  grant insert on testdb.* to [email protected]‘%‘  grant update on testdb.* to [email protected]‘%‘  grant delete on testdb.* to [email protected]‘%‘
2 或者,用一条 MySQL 命令来替代:
3 grant select, insert, update, delete on testdb.* to [email protected]‘%‘  

二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。 
grant 创建、修改、删除 MySQL 数据表结构权限

1 grant create on testdb.* to [email protected]‘192.168.0.%‘ ;
2 grant alter  on testdb.* to [email protected]‘192.168.0.%‘ ;
3 grant drop   on testdb.* to [email protected]‘192.168.0.%‘ ; 

grant 操作 MySQL 外键权限

grant references on testdb.* to [email protected]‘192.168.0.%‘ ;  

grant 操作 MySQL 临时表权限

grant create temporary tables on testdb.* to [email protected]‘192.168.0.%‘ ;  

grant 操作 MySQL 索引权限

grant index on  testdb.* to [email protected]‘192.168.0.%‘ ;  

grant 操作 MySQL 视图、查看视图源代码权限

grant create view on testdb.* to [email protected]‘192.168.0.%‘ ;
grant show   view on testdb.* to [email protected]‘192.168.0.%‘ ;  

grant 操作 MySQL 存储过程、函数权限

1 grant create routine on testdb.* to [email protected]‘192.168.0.%‘ ;  -- now, can show procedure status
2 grant alter  routine on testdb.* to [email protected]‘192.168.0.%‘ ;  -- now, you can drop a procedure
3 grant execute        on testdb.* to [email protected]‘192.168.0.%‘ ; 

三、grant 普通 DBA 管理某个 MySQL 数据库的权限

grant all privileges on testdb to [email protected]‘localhost‘  其中,关键字 “privileges” 可以省略。

四、grant 高级 DBA 管理 MySQL 中所有数据库的权限

 grant all on *.* to [email protected]‘localhost‘  

五、MySQL grant 权限,分别可以作用在多个层次上

1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to [email protected] ; -- dba 可以查询 MySQL 中所有数据库中的表。
grant all    on *.* to [email protected] ; -- dba 可以管理 MySQL 中的所有数据库 

2. grant 作用在单个数据库上:

grant select on testdb.* to [email protected] ; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to [email protected] ;  

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to [email protected] ;  

5. grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to ‘dba‘@‘localhost‘
grant execute on function  testdb.fn_add to ‘dba‘@‘localhost‘ 

六、查看 MySQL 用户权限 查看当前用户(自己)权限: show grants; 
查看其他 MySQL 用户权限: show grants for [email protected]; 
七、撤销已经赋予给 MySQL 用户权限的权限

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
grant  all on *.* to   [email protected];
revoke all on *.* from [email protected]; 

八、MySQL grant、revoke 用户权限注意事项

1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。 
2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“ 
grant select on testdb.* to [email protected] with grant option; 这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。

九 . FLUSH   PRIVILEGES;  这样权限才会生效 不然要重新连接数据库 或者重启数据库

原文地址:https://www.cnblogs.com/zengpeng/p/9315242.html

时间: 2024-08-03 21:49:40

mysql 授权命令的相关文章

2.MySQL授权命令grant的使用方法

本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant select on testdb.* to [email protected]'%'grant insert on testdb.* to [email protected]'%'grant update on testdb.* to [email pro

MySQL授权命令grant的使用方法

本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant select on testdb.* to [email protected]'%'grant insert on testdb.* to [email protected]'%'grant update on testdb.* to [email pro

13.1 设置更改root密码;13.2 连接MySQL;13.3 MySQL常用命令

扩展 : mysql5.7 root密码更改 http://www.apelearn.com/bbs/thread-7289-1-1.html myisam 和innodb引擎对比 http://www.pureweber.com/article/myisam-vs-innodb/ mysql 配置详解: http://blog.linuxeye.com/379.html mysql调优: http://www.aminglinux.com/bbs/thread-5758-1-1.html 同学

MongoDB与Mysql常用命令解释

原文 本文旨在介绍MongoDB,Mysql的常用命令:将MongoDB 和传统的关系型数据库的常用命令对照起来学习,更加便于记忆和理解. mongodb与mysql命令对比 MongoDB是由数据库(database/repository).集合(collection).文档对象(document)三个层次组成.MongoDB中集合对应关系型数据库里的表,但是集合中没有列.行和关系的概念,这体现了模式自由的特点. 传统的关系数据库一般由数据库(database).表(table).记录(rec

MYSQL常用命令集合(转载)

文章出处:http://www.cnblogs.com/q1ng/p/4474501.html 1.导出整个数据库mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1)mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u wcnc -p

mysql常用命令大全(百度文库下载的,备忘一下)

一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.例1:连接到本机上的MYSQL. 首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是: mysql>. 2.例2:连接到远程主机上的MYSQL.假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123.则

MYSQL常用命令集合

1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql 3.导

mysql常用命令整理

整理下常用命令,方便记忆,没事可拿出来瞅瞅,: 1.连接mysql数据库: #mysql -h 1.1.1.1 -uroot -p zabbix 2.mysql改密码 mysqladmin命令格式: mysqladmin -u 用户名 -p 旧密码 password 新密码(password函数) 2)忘记root密码 # vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 重新启动mysqld 3.mysql建新用户并授权 grant selec

烂泥:mysql帮助命令使用说明

本文首发于烂泥行天下. 在安装.管理和使用mysql过程中,你是不是需要记忆很多的mysql命令.而且对于新手来说,很不多的命令不知道该如何应用,对于老手来说很多命令时间长了忘记具体的用法. 其实mysql的帮助信息,已经给我们提供很全面的使用方法. 下面我就大致介绍下,如何使用mysql的帮助信息. 说明:在此我只是为学习mysql提供一个思路,本篇文章不会过多讲解每一个命令的使用方法. 一.mysql数据库初始化 在安装mysql进行初始化时,我们要使用mysql_install_db脚本进