zoukankan      html  css  js  c++  java
  • Python 44 存储引擎 索引 日志查找 权限

    前天内容回顾:
     PyMySQL:
      SQL注入:
       原因: 相信用户输入的所有的数据
       方法:
        1. 自己手动去判断转义用户输入的数据
        2. 不要拼接SQL语句, 使用PyMySQL中的execute方法, 防止SQL的注入
     事务:
     
      四大特性:
       原子性: 一组操作, 要么全部成功, 要么全部失败
       一致性: 操作之前和操作之后, 总的金额是一致的
       隔离性: 本次事物的操作对其他事务的操作是没有任何影响的
       持久性: 当我们commit/rollback之后, 影响就已经生效了, 补偿性事务来解决
     
      开启: start transaction
      一组SQL语句的操作
      完成(commit/rollback)
      
      ps :
       针对mysql的:
        start transaction
        drop table t1;
        rollback;
       其他的数据库中也是一样的, 但是除了oracle(flashback)
     
     视图, 函数, 触发器, 存储过程
     
     现在阿里云上, 数据库不建议使用外键
     
    今天内容:
    存储引擎
    索引
    日志查找 
    权限
     
     存储引擎:
      
      create table t1(
       id int auto_increment primary key,
       name varchar(32) not null default ''
      )engine=Innodb charset=utf8;
      
      分类: (****************)
       Innodb
        1.(默认版本包含5.5)
        2.支持事务
        3.不支持全文索引
        4.索引和数据都是在同一个文件中, .ibd
          表的结构实在.frm文件中
       MyIsam
        1.(默认版本5.5以下 5.3)
        2.不支持事务
        3.支持全文索引
        4..frm: 表结构
          .MYD: 表数据
          .MYI: 表索引
         
         
       memory
        
       全文索引:
        sphinx
      
     索引:
      
      作用: 加快查询的速度
      
      类比: 新华字典的目录, 可以将索引理解成一个特殊的文件, 然后如果没有这个文件的话, 查询是从前到后查找数据的,
          如果有这个文件的话, 会按照一种特殊的数据结构(二叉树)查找数据
      
      分类:
       主键索引: 加快查询 + 不能重复 + 不能为空  primary key
       唯一索引: 加快查询 + 不能重复   unique(列名)
        联合唯一索引: 加快查询 + 不能重复 unique(列名1,列名2)
       普通索引: 加快查询    index('列名')
      
      
      创建:
       
       主键索引:
        第一种:
         create table t1(
          id int auto_increment primary key,
          name varchar(32) not null default ''
         )engine=Innodb charset=utf8;
        第二种:
         alter table t1 change id id int  auto_increment primary key;
         
       唯一索引:
       
        第一种:
         create table t1(
          id int auto_increment primary key,
          name varchar(32) not null default '',
          unique ix_name ('name')
         )engine=Innodb charset=utf8;
         
        第二种:
         create unique index 索引名称(ix_name) on 表名(t1)(name);
         create unique index 索引名称(ix_name_age) on 表名(t1)(name,age);
       
       普通索引:
       
        第一种:
         create table t1(
          id int auto_increment primary key,
          name varchar(32) not null default '',
          index ix_name ('name')
         )engine=Innodb charset=utf8;
         
        第二种:
         create  index 索引名称(ix_name) on 表名(t1)(name);
       
       删除:
        drop index 索引名称(ix_name) on 表名(t1);
        
      场景:
       使用频繁的列上加一个索引
        
      索引的缺点:
       
       版本5.3以下:
        删除和修改的速度就变慢了
       
       版本5.5以上:
        删除和修改的速度不是特别的慢
      
       create table t12(
        id int auto_increment primary key,
        name varchar(32) not null default '',
        email varchar(32) not null default ''
       )engine=Innodb charset=utf8;
       
      
      索引的使用:
       
       explain 工具
       
       查看sql语句是否用的上索引, 或者查看sql执行效率的工具
       
       给执行的SQL语句出一个报告, 通过此报告来判断sql语句的执行效率和效果
       
       ES (elasticsearch )
       SQL语句的规则:
       
        - 不建议使用 like 进行搜索
        - 组合索引最左前缀
         如果组合索引为:(name,email)
         where name and email       -- 使用索引
         where name                 -- 使用索引
         where email                -- 不使用索引
       
      慢日志查询(slow log):
       
       日志文件: 记录了执行速度特别慢的SQL语句
       
       开启的步骤:
        1. show variables like '%query%';
        
        2. set global long_query_time = 1; 设置慢查询的时间
        3.  slow_query_log = ON                                                 
        4.  slow_query_log_file  = E:programmysql-5.6.44-winx64dataoldboy-slow.log
      普通日志记录(general  log):
       
       SQL审计 (记录sql的操作语句)
       
       show variables like '%general%';
       +------------------+------------------------------------------------+
       | Variable_name    | Value                                          |
       +------------------+------------------------------------------------+
       | general_log      | ON                                             |
       | general_log_file | E:programmysql-5.6.44-winx64dataoldboy.log |
       +------------------+------------------------------------------------+
       set global general_log = ON;
       
      
      权限管理:
       
       创建用户
        create user '用户名'@'IP地址' identified by '密码';
        creaee user 'zekai'@'192.168.1.123' identified by '123qwe';
        creaee user 'zekai'@'192.168.1.%' identified by '123qwe';
        create user 'zekai'@'%' identified by '123qwe';
        
       删除用户
        drop user '用户名'@'IP地址';
       修改用户
        rename user '用户名'@'IP地址' to '新用户名'@'IP地址';
        
       修改密码
        set password for '用户名'@'IP地址' = Password('新密码')
       
       授权:
        grant  权限 on 数据库.表 to   '用户'@'IP地址'      -- 授权
        
        grant select on db1.*  to 'zekai'@'%';
        grant select on *.*  to 'zekai'@'%';
        grant select, insert, delete on db1.*  to 'zekai'@'%';
       
       记住:
        flush privileges;
      
  • 相关阅读:
    SQL最小 最大时间 查询
    Linq Except,Distinct,Left Join
    Js 刷新页面
    olgaInteractive Shape Modeling(0)
    olgaInteractive Shape Modeling(1):classmaterials
    olgaInteractive Shape Modeling(1):classmaterials:Shape Creation and Deformation
    olgaInteractive Shape Modeling(2):related papers
    计算机内部如何存储数据,关于源码、补码的问题!
    sprintf用法解析
    堆与栈有什么区别?
  • 原文地址:https://www.cnblogs.com/llx--20190411/p/11042563.html
Copyright © 2011-2022 走看看