mysql_2_兄弟连笔记

来源:互联网 发布:空间数据质量控制 编辑:程序博客网 时间:2024/06/18 15:10
1, bin_log:
   加锁备份:mysqldump -Uxxx -Pxxx test -l -F > ./db.sql 
   导入: mysql -Uxxx -Pxxx test < ./db.sql 
   回复bin_log: 
      show master status,得到对应的bin_log
      mysqlbinlog -Uxxx -Pxxx test xxxx.log  
   
2, 主重复制:
   1) 在my.cnf设置 service_id =
   2) 授权grant *.* on user@192.168.1.2 
   3)在从机的my.cnf设置, master_host, master_port, service_id,
   
3, 分区
   1) MyISAM: 分区的表查询较快;无分区、分区查询时,加入索引,查询效率一样
   2)Innodb: 索引、数据放在同一个文件。
      共享表空间: 默认为ibdata1,
 独立表空间: my.conf ---> innodb_file_per_table = true; 
              创建二个文件: 表结构放一个文件;数据、索引共放在一个文件。


4,优化技巧:
   1)正则表达式:REGEXP
   2)group by with rollup
   3) order by rand()
   4) bit_or / bit_and
   5) innodb 引擎的外键,是关联其它表的主键
   6)帮助:? %
   
5, 索引:
   1)查看: show global status like 'Com_insert%' 
      如果是innodb: show global status like 'innodb_rows%'
 show global status like 'connections';
      show global status like 'uptime';
      show global status like 'slow_queries';
      
      show variables like '%slow%';
      show variables like 'long_query_time';
 
2) desc/explain SQL
 索引type: 
         rang
     const:
     con_ref
     ref:
 rows: 影响行数
    3)如何使用索引:
  a, like 不以%开始
  b, is null 可以使用索引
  c, and/or 二边的条件也是索引
  d, 字符类型的列时,要使用引号
  e, 复合索引,最左边的列为条件时,才使用索引  
4)检查命令:
  check table/view
  optimize table: 释放多余空间
5) 导入、导出数据:
  select * from t1 into output file 
  load data inputfile xxxx into table XXX
6) 优化技巧:
  group by XXX order by null
  
  insert into XXX value (),(),()
  
  不使用子查询,尽量用join
  
  alter table disable keys
  load data 
  alter table enable keys
  
  set unique_checks = 0
  set unique_checks = 1
  
  set auto_commit = 0
  set auto_commit = 1 
  
7) 字符集:
  show variables like '%character%'
8)bin_log
  show variables like '%log_bin%'
9) slow_queries
  show variables like '%slow_query_log%';
       show variables like '%long_query_time%';
0 0
原创粉丝点击