在mysql下mysql库中有6个权限表

mysql.user

用户字段,权限字段,安全字段,资源控制字段

mysql.db 、 mysql.host

用户字段,权限字段

mysql.tables_priv,mysql.columms_priv,mysql.procs_priv

一、用户管理

(1)创建用户的三种方法

.create user user1@'localhost' identified  by '';
.insert into mysql.user(user,host,password,ssl_cipher,x509_issuer,x509_subject) values('user2','localhost',password(''),'','','');
.grant select on *.* to user3@'localhost' identified by '' //授select权所有库和所有表给user3,密码123
flush privileges

(2)删除用户

.drop user user1@'localhost'
.delete from mysql.user where user='user1' and host='localhost';

(3)root用户修改自己密码

.mysqladmin -uroot -proot password ''
.update mydql.user set password=password('new_password') where user='root' and host='localhost';
.set password=password('new_password')
flush privileges //刷新授权表

(4)root用户修改其他用户密码

.set password for user3@'localhost' =password('new_password');
flush privileges;
.updatae mysql.user set password=password('new_password') where user='user3' and host='localhost';
flush privileges;
.grant select on *.* to user3@'localhost' identified by 'pwd';
flush privileges;

(5)普通用户修改自己密码

set password=password('new_password');

(6)丢失root用户密码

vim /etc/my.cnf
skip-grant-tables//将这句话的注释去掉
service mysqld restart
mysql -uroot //然后就可以跳过权限表进入mysql
update mysql.user set password=password('new_password') where user='user3' and host='localhost';
flush privileges;
\q //退出mysql
vim /etc/my.cnf
#skip-grant-tables //将这句话再重新注释

二、权限管理

语法格式:grant 权限列表 on 库名.表名 to 用户名@'客户端' [identified by 'password' with grant option]

其中:with_option参数如下

grant option: 授权选项
max_queries_per_hour:定义每小时允许执行的查询数
max_updates_per_hou:定义每小时允许执行的更新数
max_connections_per-hour:定义每小时可以建立的连接数
max-user_connections:定义单个用户同是可以建立的连接数

授权示例

grant all on *.* to admin1@'%' identified by 'password';
grant all on *.* to admin2@'%' identified by 'pw' with grant option;
grant all on *.* bbs.* to admin3@'%' identified by 'pw';
grant all on bbs.user to admin4@'%' identified by 'pw';
grant select(col1),insert(col2,col3) on bbs.user to admin5@'%' identified by 'pw'; flush privileges

查看权限

show grants for admin@'%' \G;

回收权限 revoke 权限列表 on 数据库名 from 用户名@'客户端主机'

.revoke delete on *.* from admin@'%';//回收部分权限
.revoke all privileges on *.* from admin@'%';
revoke grant on *.* from admin@'%'; //回收全部权限(包括授权)
flush privileges; //刷新授权

Mysql安全机制的更多相关文章

  1. MYSQL内存--------启动mysql缓存机制,实现命中率100% 转

    虽然这个标题夸张得过了头,但此文很完整,值得学习.转自 http://www.yy520.net/read.php?278 myql优化,启动MySQL缓存机制,实现命中率100% 配置你的mysql ...

  2. Mysql锁机制介绍

    Mysql锁机制介绍 一.概况MySQL的锁机制比较简单,其最显著的特点是不同的存储引擎支持不同的锁机制.比如,MyISAM和MEMORY存储引擎采用的是表级锁(table-level locking ...

  3. Mysql锁机制--索引失效导致行锁变表锁

    Mysql 系列文章主页 =============== Tips:在阅读本文前,最好先阅读 这篇(Mysql锁机制--行锁)文章~ 在上篇文章中,我们看到InnoDB默认的行锁可以使得操作不同行时不 ...

  4. mysql锁机制详解

    前言 大概几个月之前项目中用到事务,需要保证数据的强一致性,期间也用到了mysql的锁,但当时对mysql的锁机制只是管中窥豹,所以本文打算总结一下mysql的锁机制. 本文主要论述关于mysql锁机 ...

  5. mysql 缓存机制

    了解mysql缓存吗(顺丰) mysql缓存机制就是缓存sql 文本及缓存结果,用KV形式保存再服务器内存中,如果运行相同的sql,服务器直接从缓存中去获取结果,不需要在再去解析.优化.执行sql. ...

  6. 对mysql锁机制的学习

    1.对于mysql学习,经常翻看一些博客,论坛,好像或多或少有mysq锁机制的学习与总结,所以今天有必要 对mysql锁机制的一些个人的总结,以便以后深入的学习. 2.学习这件事,从来都是“深入浅出” ...

  7. mysql锁机制整理

    Auth: jinDate: 20140506 主要参考整理资料MYSQL性能调优与架构设计-第七章 MYSQL锁定机制http://www.cnblogs.com/ggjucheng/archive ...

  8. MySQL事物机制具备四点:简称ACID操作

    MySQL事物机制具备四点:简称ACID操作 1.原子性:要么都做,要么都不做(两条数据(写入和存储)一步未成功,整体回滚) 2.一致性:数据库的状态改变(两条数据(写入和存储)均成功,符合原子性,但 ...

  9. mysql锁机制(转载)

    锁是计算机协调多个进程或线程并发访问某一资源的机制 .在数据库中,除传统的 计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是所 ...

  10. MySQL 索引机制

    MySQL 原理篇 MySQL 索引机制 MySQL 体系结构及存储引擎 MySQL 语句执行过程详解 MySQL 执行计划详解 MySQL InnoDB 缓冲池 MySQL InnoDB 事务 My ...

随机推荐

  1. 关于JS变量和作用域

    ECMAScript 变量:1.基本类型值(简单数据段) 2.引用类型值(可能由过个值构成的对象) → 保存在内存中的对象 动态属性: 只能给引用型值动态添加新属性,以便将来使用. 复制变量值 : 基 ...

  2. Ubuntu下安装arm-linux-gcc

    安装步骤: 这里采用友善之臂发布的arm-linux-gcc-4.4.3.tar.gz软件包. 一.将压缩包arm-linux-gcc-4.4.3.tar.gz存放在opt目录下. 执行解压命令:su ...

  3. 使用jquery插件uploadify上传文件的方法与疑问

    我是学生一枚,专业也不是计算机,但又要用到很多相关技术,所以在技术基础不牢靠的情况下,硬着头皮在做.最近在做一个小项目需要上传图片,而且是需要用ajax的方式.但是利用jquery的ajax方法总会有 ...

  4. PNG图片小结

    PNG: 便携式网络图形(Portable Network Graphics,PNG)是一种无损压缩的位图图形格式,支持索引.灰度.RGB三种颜色方案以及Alpha通道等特性.PNG的开发目标是改善并 ...

  5. UVa230 Borrowers (STL)

     Borrowers  I mean your borrowers of books - those mutilators of collections, spoilers of the symmet ...

  6. 循环-10. 求序列前N项和*

    /* * Main.c * C10-循环-10. 求序列前N项和 * Created on: 2014年7月30日 * Author: Boomkeeper *******部分通过******* */ ...

  7. MFC 遍历FTP服务器目录相关

    CInternetSession* pSession; pSession = new CInternetSession;  //构造新的连接 CFtpConnection* pFtpCon; pFtp ...

  8. (Inno setup打包)检测系统是否已安装程序,若已安装则弹出卸载提示的代码

    原文 http://bbs.itiankong.com/thread-30983-1-5.html 有6天没研究pascal代码了,昨天晚上突然来了灵感,终于解决了苦思冥想好几天没能解决的问题, 因此 ...

  9. select自动选中

    //筛选 var typeid = "<!--{$typeid}-->"; var bigclassid = "<!--{$bigclassid}--& ...

  10. LInux 下挂在Windows共享文件夹

    挂载WIndow共享文件夹  //192.168.0.103/software mount -t smbfs -o username=administrator,password=“de123”  / ...