我们在一个MySQL数据库中有4个非常大的表。它们大约有50、35、6和5 Gb,其他表就没有那么大了。这些表充满了分析数据,每隔10分钟就会追加一次cron任务。随着时间的推移,这些表将继续增长。
下面是datatable的架构
CREATE TABLE `instpld` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`insID` varchar(100) NOT NULL,
`dbID` int(10) NOT NULL,
`type` varchar(1) NOT NULL,
`timestamp` int(11) NOT NULL,
`count` text NOT NULL,
`comment_count` int(10) NOT NULL,
PRIMARY KEY (`id`),
KEY `insID` (`insID`(50)),
KEY `dbID` (`dbID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;我知道字段的类型可以更好。问题是哪一个更好-在表上添加一些分区,还是将所有东西都切换到MangoDB,因为它更快?
我正在寻找每个选项的利弊。
# Misc Settings
# -------------
datadir=/var/lib/mysql
tmpdir=/var/lib/mysqltmp
socket=/var/lib/mysql/mysql.sock
#skip-locking
skip-name-resolve
#table_cache=2048
thread_cache_size=16
back_log=100
max_connect_errors=10000
open-files-limit=20000
interactive_timeout=3600
wait_timeout=600
#max_connections=200
# Added to prevent DNS lookups from causing performance issues
skip-name-resolve
# Set this to change the way MySQL handles validation, data
# conversion, etc. Be careful with this setting as it can
# cause unexpected results and horribly break some applications!
# Note, too, that it can be set per-session and can be hard set
# in stored procedures.
#sql_mode=NO_ENGINE_SUBSTITUTION
# Slow Query Log Settings
# -----------------------
#log-slow-queries=/var/lib/mysqllogs/slow-log
#long_query_time=2
#log-queries-not-using-indexes
# Global, Non Engine-Specific Buffers
# -----------------------------------
max_allowed_packet=16M
tmp_table_size=64M
max_heap_table_size=64M
# Generally, it is unwise to set the query cache to be
# larger than 64-128M as this can decrease performance
# since the penalty for flushing the cache can become
# significant.
query_cache_size=32M
skip-name-resolve
# Set this to change the way MySQL handles validation, data
# conversion, etc. Be careful with this setting as it can
# cause unexpected results and horribly break some applications!
# Note, too, that it can be set per-session and can be hard set
# in stored procedures.
#sql_mode=NO_ENGINE_SUBSTITUTION
# Slow Query Log Settings
# -----------------------
#log-slow-queries=/var/lib/mysqllogs/slow-log
#long_query_time=2
#log-queries-not-using-indexes
# Global, Non Engine-Specific Buffers
# -----------------------------------
max_allowed_packet=16M
tmp_table_size=64M
max_heap_table_size=64M
# Generally, it is unwise to set the query cache to be
# larger than 64-128M as this can decrease performance
# since the penalty for flushing the cache can become
# significant.
query_cache_size=32M
# Per-Thread Buffers
# ------------------
sort_buffer_size=1M
read_buffer_size=1M
read_rnd_buffer_size=8M
join_buffer_size=1M
key_buffer_size=64M
# This setting controls the size of the buffer that is allocated when
# sorting MyISAM indexes during a REPAIR TABLE or when creating indexes
# with CREATE INDEX or ALTER TABLE.
myisam_sort_buffer_size=64M
# InnoDB
# ------
# Note: While most settings in MySQL can be set at run-time, InnoDB
# variables require restarting MySQL to apply.
# If the customer already has InnoDB tables and wants to change the
# size of the InnoDB tablespace and InnoDB logs, then:
# 1. Run a full backup with mysqldump
# 2. Stop MySQL
# 3. Move current ibdata and ib_logfiles out of /var/lib/mysql
# 4. Uncomment the below innodb_data_file_path and innodb_log_file_size
# 5. Start MySQL (it will recreate new InnoDB files)
# 6. Restore data from backup
#innodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_file_size=100M
innodb_buffer_pool_size=2G
........发布于 2015-03-24 07:38:17
你有128 of的内存,使用它吧!innodb_buffer_pool_size=2G --更改为内存的70%左右。
我敢打赌,你不能给我看一个使用KEY instaID (instaID(50))的EXPLAIN。前缀、索引几乎总是未使用的。
打开慢日志,收集一些数据,运行pt- query -digest,然后向我们显示“最差”的查询。为它提供EXPLAIN SELECT ...。
id int(20) NOT NULL AUTO_INCREMENT, --我希望您不会期望20位数字。这将最多略高于20亿。
如果我们不能优化您的查询,那么我们将转向数据仓库技术,例如汇总表--它们往往会带来10倍的速度提升。
发布于 2015-03-24 01:01:17
如果不知道你是如何使用它的,或者你首先会面临什么瓶颈,你就真的不可能回答。
请记住,如果您不偶尔优化表,Innodb在大小方面会有一些问题。
https://stackoverflow.com/questions/29215841
复制相似问题