-
Notifications
You must be signed in to change notification settings - Fork 0
mysql
cmh edited this page Mar 27, 2015
·
17 revisions
###优化
####java_jdbc batch慢
innodb_flush_log_at_trx_commit = 0
- 1InnoDB InnoDB will flush (fsync) the transaction logs to the disk at each commit
- 0the log is only written to the log file and the log file flushed to disk approximately once per second
- the log is written to the log file at each commit, but the log file is only flushed to disk approximately once per second.
- 默认为1或者不开启
####连接数不够
max_connections = 1000
SELECT @@MAX_CONNECTIONS;
####避免表扫描
- 利用query_cache,调整sql语句写法
- Force index(createtime),告知mysql优化器,避免表扫描
SELECT missionid,nodeid FROM task_history FORCE INDEX(missionid) WHERE missionid IN ( %s ) AND nodetype= 2 AND type=4 - 建立联合索引createtime_nodetype_type,并且强制走索引
实际测试结果表明并不是每次都优于单独索引,和数据规模有比较大的关系
####查询数据库大小
- use information_schema
- select * from information_schema.TABLES where information_schema.TABLES.TABLE_SCHEMA='encodeonline' and information_schema.TABLES.TABLE_NAME='encode_task_history'\G
- select concat(round(sum(data_LENGTH)/(1024*1024),2),'MB') as 'Data Size' from tables where table_schema='encodeonline' 数据库表大小
- select concat(round(sum(index_LENGTH)/(1024*1024),2),'MB') as 'Data Size' from tables where table_schema=''encodeonline'' 数据库索引大小
###常用命令