在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获取昨天日期

    刚刚js做项目,遇到需要获取昨天日期的问题,网上找了下答案,感觉网上的答案都不太严谨,自己写了个,凑合能用吧,忘大神们抛砖指教. <script type="text/javascri ...

  2. Perfect Squares

    Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...

  3. nodejs iconfont处理

    做前端优化,iconfont可以替换掉很多图片,减少请求,并有很好的兼容性,颜色大小也有很好的自由度.现在网上已经有很多公开的iconfont供我们使用.但是每个项目有不同的应用场景,网上的并不能满足 ...

  4. Win32 多线程的创建方法和基本使用

    Win32多线程的创建方法主要有: (1)CreateThread() (2)_beginthread()&&_beginthreadex() (3)AfxBeginThread() ...

  5. hdu 4906 3-idiots fft

    题目链接 n个火柴棍取3个, 问能组成三角形的概率是多少. kuangbin大神的博客写的很详细了..http://www.cnblogs.com/kuangbin/archive/2013/07/2 ...

  6. 转——iptables详细配置

    基本原理及命令使用  http://my.oschina.net/hevakelcj/blog/313212 基础知识 Linux系统内核内建了netfilter防火墙机制.Netfilter(数据包 ...

  7. 1021 Fibonacci Again (hdoj)

    Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) ...

  8. Max Sum(hd P1003)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  9. Lowest Bit(hdoj1196)

    Lowest Bit Problem Description Given an positive integer A (1 <= A <= 100), output the lowest ...

  10. SQL Server 无法启动的 4 种原因

    SQL Server 无法启动的原因定位.首先要知道SQL Server 启动的过程. 第一步: 读取注册表,创建log文件.检测硬件.初始化系统配置. 第二步: 启动系统数据库. 第三步: 准备好网 ...