我有一个Ubuntu 64位系统,运行Mysql版本5.5.32-0ubuntu0.12.04.1-log。该机器有 64 GB 内存。
我有一个相当庞大的数据库,几乎有 90 GB 的数据和一个包含 250.000.000 行的表。
我的问题是,mysqld 进程并不占用太多内存。仅在 2-5 GB 之间。但系统内存全部用于文件缓存。
我重新启动服务器,还有 63 GB 可用内存。一旦开始执行较大的查询,可用内存量就会减少,而缓存的文件量会增加。 所以mysql并没有将数据加载到RAM中,而是使用文件缓存。 查询速度非常慢。当我查询大表时,根据解释,该表使用索引并且只需要考虑 500.000 行,这需要几分钟的时间。
对于这个现象你有什么解释吗?
这是我的 my.cnf。 (这实际上是我的从站的配置,但它显示了完全相同的行为)我的表都是 InnoDB:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 127.0.0.1
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
[innodb]
innodb_buffer_pool_size = 55G
innodb_log_file_size = 256M
innodb_log_buffer_size = 4M
innodb_flush_log_at_trx_commit=2
innodb_thread_concurrency=0
innodb_file_per_table = 1 # (this is not respected as I changed it after the first database was created). So my ibdata1 file is over 80GB in size
max_connections = 1000 # wenn gleichzeitig viele User zugreifen
table_cache = 10000 # abgeleitet von max_connections, könnte sogar höher sein
tmp_table_size = 5000M # wichtig wg. JOINs, zu kleiner Wert macht die extrem langsam
max_heap_table_size = 5000M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/
最佳答案
将 key_buffer 大小增加到 128M
,将 max_allowed_packet 增加到 128M
,因为这将加快查询的执行速度
关于Mysql使用系统文件缓存,而不是直接使用RAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22527669/