我有一个包含 100,000 个表的 MySQL。这是目前对我的系统来说最好的设计,因为这些表彼此不相关,并且选择查询只会在单个表上关闭。此外,用户很可能不会经常访问相同的表。
我有 16GB RAM,但大约一天后,MySQL 消耗了其中的 90%,而我的系统总内存使用率为 99-100%。我尝试了很多东西,但根本无法降低内存使用量。
我innodb_buffer_pool_size
目前是 8GB,但我在 1G 时遇到了同样的问题。我也尝试减少open_files_limit
,但这也无济于事。
这是我的输出
SHOW GLOBAL STATUS LIKE '%Open_%';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| Com_show_open_tables | 0 |
| Innodb_num_open_files | 431 |
| Open_files | 0 |
| Open_streams | 0 |
| Open_table_definitions | 615 |
| Open_tables | 416 |
| Opened_files | 4606655 |
| Opened_table_definitions | 4598528 |
| Opened_tables | 4661002 |
| Slave_open_temp_tables | 0 |
| Table_open_cache_hits | 30024782 |
| Table_open_cache_misses | 4661002 |
| Table_open_cache_overflows | 4660579 |
+----------------------------+----------+
这是我的 mysqld 配置:
sql-mode=''
innodb_buffer_pool_size = 8G
open_files_limit=100000
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_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover-options = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
有人知道如何有效地处理这数千张桌子吗?
附加信息
A)Mysqld:https ://pastebin.com/PTiz6uRD
B)显示全球状态:https ://pastebin.com/K4sCmvFz
C) 显示全局变量:https ://pastebin.com/Cc64BAUw
D) MySQLTuner:https ://pastebin.com/zLzayi56
E) 显示引擎 INNODB 状态:https ://pastebin.com/hHDuw6gY
F) 顶部:https ://pastebin.com/6WYnSnPm
服务器重启后的测试(消耗小内存):
A) ulimit -a: https://pastebin.com/FmPrAKHU
B)iostat -x:https ://pastebin.com/L0G7H8s4
C) df -h: https://pastebin.com/d3EttR19
D) MySQLTuner:https ://pastebin.com/T3DYDLg8