首页 > 解决方案 > Mysql 使用了所有内存

问题描述

总结: MySql经过几天的运行消耗了所有内存并崩溃了

软件版本: 发行商 ID:Ubuntu 描述:Ubuntu 18.04.5 LTS 版本:18.04 代号:bionic

Linux 4.15.0-147-通用

服务器版本:8.0.24 MySQL 社区服务器

Apr 30 11:37:27 mysql8 kernel: [1101229.680225] Out of memory: Kill process 114869 (mysqld) score 966 or sacrifice child
Apr 30 11:37:27 mysql8 kernel: [1101229.680672] Killed process 114869 (mysqld) total-vm:42088196kB, anon-rss:31660624kB, file-rss:0kB, shmem-rss:0kB
Apr 30 11:37:29 mysql8 kernel: [1101232.305965] oom_reaper: reaped process 114869 (mysqld), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

设置这些值以使 Max MySQL 内存为 11.3G。总缓冲区:6.0G 全局 + 33.9M 每个线程(最大 160 个线程)。服务器有 32GB RAM,只运行 MySql

root@mysql8:~# ./mysqltuner.pl
 >>  MySQLTuner 1.8.1 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.pl/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 8.0.24
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql/error.log exists
[--] Log file: /var/log/mysql/error.log(37K)
[OK] Log file /var/log/mysql/error.log is not empty
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb
[OK] Log file /var/log/mysql/error.log is readable.
[!!] /var/log/mysql/error.log contains 198 warning(s).
[!!] /var/log/mysql/error.log contains 2 error(s).
[--] 14 start(s) detected in /var/log/mysql/error.log
[--] 1) 2021-07-21T06:15:50.156309Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
[--] 2) 2021-07-21T06:15:45.194534Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 3) 2021-07-18T16:23:42.158755Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
[--] 4) 2021-07-18T16:23:40.462353Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 5) 2021-07-14T10:15:57.572447Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
[--] 6) 2021-07-14T10:15:53.448147Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 7) 2021-07-08T08:20:48.094250Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
[--] 8) 2021-07-08T08:20:45.563321Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 9) 2021-07-04T08:48:13.422691Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
[--] 10) 2021-07-04T08:48:12.547357Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
[--] 8 shutdown(s) detected in /var/log/mysql/error.log
[--] 1) 2021-07-21T06:15:32.931850Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 2) 2021-07-18T16:23:31.840652Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 3) 2021-07-14T10:15:42.415773Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 4) 2021-07-08T08:20:35.530622Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 5) 2021-07-04T08:46:53.335155Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 6) 2021-07-04T08:45:28.582107Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 7) 2021-07-04T08:36:07.392398Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.
[--] 8) 2021-07-04T08:34:09.116853Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.24)  MySQL Community Server - GPL.

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 11.7G (Tables: 703)
[--] Data in MyISAM tables: 316.2M (Tables: 5)
[!!] Total fragmented tables: 2

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[--] Skipped due to unsupported feature for MySQL 8

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 1h 48m 50s (1M q [223.509 qps], 2K conn, TX: 5G, RX: 1G)
[--] Reads / Writes: 98% / 2%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory     : 31.4G
[--] Max MySQL memory    : 11.3G
[--] Other process memory: 0B
[--] Total buffers: 6.0G global + 33.9M per thread (160 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 7.5G (23.99% of installed RAM)
[OK] Maximum possible memory usage: 11.3G (36.12% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 3% (48K/1M)
[OK] Highest usage of available connections: 28% (45/160)
[OK] Aborted connections: 1.51%  (42/2784)
[--] Query cache have been removed in MySQL 8
[OK] Sorts requiring temporary tables: 0% (104 temp sorts / 39K sorts)
[!!] Joins performed without indexes: 13143
[OK] Temporary tables created on disk: 0% (131 on disk / 391K total)
[OK] Thread cache hit rate: 98% (45 created / 2K connections)
[OK] Table cache hit rate: 91% (1M hits / 2M requests)
[OK] table_definition_cache(2000) is upper than number of tables(1438)
[OK] Open file limit used: 0% (26/10K)
[OK] Table locks acquired immediately: 100% (2K immediate / 2K locks)
[OK] Binlog cache memory access: 98.35% (5712 Memory / 5808 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[--] MyISAM Metrics are disabled on last MySQL versions.

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 6.0G/11.7G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (16.6666666666667 %): 512.0M * 2/6.0G should be equal to 25%
[!!] InnoDB buffer pool instances: 4
[--] Number of InnoDB Buffer Pool Chunk : 48 for 4 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.93% (290050740 hits/ 290262620 total)
[!!] InnoDB Write Log efficiency: 77.21% (157671 hits/ 204214 total)
[OK] InnoDB log waits: 0.00% (0 waits / 46543 writes)

-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine not available.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

更新:当 mysql 使用 22GB ram 时,这是 valve 的两倍,然后是最大 MySQL 内存,值为 11GB。

HTOP 屏幕

SHOW GLOBAL STATUS; 

Aborted_clients 165
Aborted_connects    42
Acl_cache_items_count   0
Binlog_cache_disk_use   616
Binlog_cache_use    96991
Binlog_stmt_cache_disk_use  0
Binlog_stmt_cache_use   3268
Bytes_received  6045922316
Bytes_sent  54971094700
Caching_sha2_password_rsa_public_key    -----BEGIN PUBLIC KEY-----
 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0efP6d9Ql944lyxK92xc
 AzZShd/wqacl5NWnwc8eFCmxagEg9iCexoxVJBHQUQrVDZpTuD80/2NEgzrqbf6n
 bVVOB2mVm58NPARTmXC0dJsuaTzBke0KHeNYbrgFr9DoE0IP4Lg2E9c6HQKvSAn9
 LHQ25q+I5Kf+uNlID9RZ+AIvE3UrbeOx...
Com_admin_commands  542
Com_assign_to_keycache  0
Com_alter_db    0
Com_alter_event 0
Com_alter_function  0
Com_alter_instance  0
Com_alter_procedure 0
Com_alter_resource_group    0
Com_alter_server    0
Com_alter_table 0
Com_alter_tablespace    0
Com_alter_user  3
Com_alter_user_default_role 0
Com_analyze 0
Com_begin   64
Com_binlog  0
Com_call_procedure  33885
Com_change_db   1611
Com_change_master   0
Com_change_repl_filter  0
Com_change_replication_source   0
Com_check   0
Com_checksum    0
Com_clone   0
Com_commit  17883
Com_create_db   1
Com_create_event    0
Com_create_function 0
Com_create_index    0
Com_create_procedure    0
Com_create_role 0
Com_create_server   0
Com_create_table    58
Com_create_resource_group   0
Com_create_trigger  0
Com_create_udf  0
Com_create_user 1
Com_create_view 0
Com_create_spatial_reference_system 0
Com_dealloc_sql 49
Com_delete  3940
Com_delete_multi    0
Com_do  0
Com_drop_db 0
Com_drop_event  0
Com_drop_function   0
Com_drop_index  0
Com_drop_procedure  0
Com_drop_resource_group 0
Com_drop_role   0
Com_drop_server 0
Com_drop_spatial_reference_system   0
Com_drop_table  16
Com_drop_trigger    0
Com_drop_user   0
Com_drop_view   0
Com_empty_query 0
Com_execute_sql 49
Com_explain_other   0
Com_flush   39
Com_get_diagnostics 0
Com_grant   7
Com_grant_roles 0
Com_ha_close    0
Com_ha_open 0
Com_ha_read 0
Com_help    0
Com_import  0
Com_insert  57210
Com_insert_select   344
Com_install_component   0
Com_install_plugin  0
Com_kill    0
Com_load    0
Com_lock_instance   0
Com_lock_tables 0
Com_optimize    4
Com_preload_keys    0
Com_prepare_sql 49
Com_purge   0
Com_purge_before_date   0
Com_release_savepoint   9
Com_rename_table    0
Com_rename_user 0
Com_repair  0
Com_replace 1
Com_replace_select  0
Com_reset   0
Com_resignal    0
Com_restart 0
Com_revoke  1
Com_revoke_all  3
Com_revoke_roles    0
Com_rollback    140
Com_rollback_to_savepoint   1151
Com_savepoint   9
Com_select  11814459
Com_set_option  58098
Com_set_password    0
Com_set_resource_group  0
Com_set_role    0
Com_signal  0
Com_show_binlog_events  1
Com_show_binlogs    4
Com_show_charsets   8
Com_show_collations 226
Com_show_create_db  0
Com_show_create_event   0
Com_show_create_func    32
Com_show_create_proc    46
Com_show_create_table   2141
Com_show_create_trigger 80
Com_show_databases  35
Com_show_engine_logs    0
Com_show_engine_mutex   0
Com_show_engine_status  18
Com_show_events 0
Com_show_errors 0
Com_show_fields 11515
Com_show_function_code  0
Com_show_function_status    10
Com_show_grants 17
Com_show_keys   2
Com_show_master_status  209
Com_show_open_tables    0
Com_show_plugins    1
Com_show_privileges 0
Com_show_procedure_code 0
Com_show_procedure_status   10
Com_show_processlist    70
Com_show_profile    0
Com_show_profiles   0
Com_show_relaylog_events    0
Com_show_replicas   4
Com_show_slave_hosts    4
Com_show_replica_status 3274
Com_show_slave_status   3274
Com_show_status 5865
Com_show_storage_engines    4
Com_show_table_status   1186
Com_show_tables 36
Com_show_triggers   1151
Com_show_variables  3310
Com_show_warnings   295
Com_show_create_user    0
Com_shutdown    0
Com_replica_start   0
Com_slave_start 0
Com_replica_stop    0
Com_slave_stop  0
Com_group_replication_start 0
Com_group_replication_stop  0
Com_stmt_execute    49
Com_stmt_close  49
Com_stmt_fetch  0
Com_stmt_prepare    49
Com_stmt_reset  0
Com_stmt_send_long_data 0
Com_truncate    49
Com_uninstall_component 0
Com_uninstall_plugin    0
Com_unlock_instance 0
Com_unlock_tables   18
Com_update  288371
Com_update_multi    5420
Com_xa_commit   0
Com_xa_end  0
Com_xa_prepare  0
Com_xa_recover  0
Com_xa_rollback 0
Com_xa_start    0
Com_stmt_reprepare  0
Connection_errors_accept    0
Connection_errors_internal  0
Connection_errors_max_connections   0
Connection_errors_peer_address  0
Connection_errors_select    0
Connection_errors_tcpwrap   0
Connections 24598
Created_tmp_disk_tables 2673
Created_tmp_files   29073
Created_tmp_tables  2048824
Current_tls_ca  ca.pem
Current_tls_capath  
Current_tls_cert    server-cert.pem
Current_tls_cipher  
Current_tls_ciphersuites    
Current_tls_crl 
Current_tls_crlpath 
Current_tls_key server-key.pem
Current_tls_version TLSv1,TLSv1.1,TLSv1.2,TLSv1.3
Delayed_errors  0
Delayed_insert_threads  0
Delayed_writes  0
Error_log_buffered_bytes    38560
Error_log_buffered_events   260
Error_log_expired_events    0
Error_log_latest_write  1626853689371451
Flush_commands  30
Handler_commit  7536527
Handler_delete  2836
Handler_discover    0
Handler_external_lock   24442935
Handler_mrr_init    0
Handler_prepare 358992
Handler_read_first  535985
Handler_read_key    348441108
Handler_read_last   344
Handler_read_next   788469182
Handler_read_prev   444
Handler_read_rnd    971184
Handler_read_rnd_next   7247264904
Handler_rollback    193
Handler_savepoint   9
Handler_savepoint_rollback  1151
Handler_update  52418514
Handler_write   66418155
Innodb_buffer_pool_dump_status  Dumping of buffer pool not started
Innodb_buffer_pool_load_status  Buffer pool(s) load completed at 210721  8:16:59
Innodb_buffer_pool_resize_status    
Innodb_buffer_pool_pages_data   380821
Innodb_buffer_pool_bytes_data   6239371264
Innodb_buffer_pool_pages_dirty  1
Innodb_buffer_pool_bytes_dirty  16384
Innodb_buffer_pool_pages_flushed    580378
Innodb_buffer_pool_pages_free   4096
Innodb_buffer_pool_pages_misc   8299
Innodb_buffer_pool_pages_total  393216
Innodb_buffer_pool_read_ahead_rnd   0
Innodb_buffer_pool_read_ahead   787663
Innodb_buffer_pool_read_ahead_evicted   992
Innodb_buffer_pool_read_requests    1976082938
Innodb_buffer_pool_reads    442288
Innodb_buffer_pool_wait_free    0
Innodb_buffer_pool_write_requests   2717746
Innodb_data_fsyncs  972858
Innodb_data_pending_fsyncs  18446744073709551544
Innodb_data_pending_reads   0
Innodb_data_pending_writes  0
Innodb_data_read    20465718272
Innodb_data_reads   1250550
Innodb_data_writes  1372515
Innodb_data_written 10448172544
Innodb_dblwr_pages_written  572434
Innodb_dblwr_writes 226408
Innodb_log_waits    0
Innodb_log_write_requests   1899344
Innodb_log_writes   510148
Innodb_os_log_fsyncs    358717
Innodb_os_log_pending_fsyncs    0
Innodb_os_log_pending_writes    0
Innodb_os_log_written   460218880
Innodb_page_size    16384
Innodb_pages_created    37059
Innodb_pages_read   1249125
Innodb_pages_written    601303
Innodb_redo_log_enabled ON
Innodb_row_lock_current_waits   0
Innodb_row_lock_time    433555
Innodb_row_lock_time_avg    6470
Innodb_row_lock_time_max    51007
Innodb_row_lock_waits   67
Innodb_rows_deleted 1474
Innodb_rows_inserted    285549
Innodb_rows_read    8210896171
Innodb_rows_updated 175486
Innodb_system_rows_deleted  1477
Innodb_system_rows_inserted 1559
Innodb_system_rows_read 5671360
Innodb_system_rows_updated  2405
Innodb_sampled_pages_read   0
Innodb_sampled_pages_skipped    0
Innodb_num_open_files   719
Innodb_truncated_status_writes  0
Innodb_undo_tablespaces_total   2
Innodb_undo_tablespaces_implicit    2
Innodb_undo_tablespaces_explicit    0
Innodb_undo_tablespaces_active  2
Key_blocks_not_flushed  0
Key_blocks_unused   6630
Key_blocks_used 151
Key_read_requests   40732
Key_reads   1382
Key_write_requests  11584
Key_writes  11584
Locked_connects 0
Max_execution_time_exceeded 0
Max_execution_time_set  0
Max_execution_time_set_failed   0
Max_used_connections    51
Max_used_connections_time   2021-07-22 11:05:05
Mysqlx_aborted_clients  0
Mysqlx_address  ::
Mysqlx_bytes_received   0
Mysqlx_bytes_received_compressed_payload    0
Mysqlx_bytes_received_uncompressed_frame    0
Mysqlx_bytes_sent   0
Mysqlx_bytes_sent_compressed_payload    0
Mysqlx_bytes_sent_uncompressed_frame    0
Mysqlx_compression_algorithm    
Mysqlx_compression_level    
Mysqlx_connection_accept_errors 0
Mysqlx_connection_errors    0
Mysqlx_connections_accepted 0
Mysqlx_connections_closed   0
Mysqlx_connections_rejected 0
Mysqlx_crud_create_view 0
Mysqlx_crud_delete  0
Mysqlx_crud_drop_view   0
Mysqlx_crud_find    0
Mysqlx_crud_insert  0
Mysqlx_crud_modify_view 0
Mysqlx_crud_update  0
Mysqlx_cursor_close 0
Mysqlx_cursor_fetch 0
Mysqlx_cursor_open  0
Mysqlx_errors_sent  0
Mysqlx_errors_unknown_message_type  0
Mysqlx_expect_close 0
Mysqlx_expect_open  0
Mysqlx_init_error   0
Mysqlx_messages_sent    0
Mysqlx_notice_global_sent   0
Mysqlx_notice_other_sent    0
Mysqlx_notice_warning_sent  0
Mysqlx_notified_by_group_replication    0
Mysqlx_port 33060
Mysqlx_prep_deallocate  0
Mysqlx_prep_execute 0
Mysqlx_prep_prepare 0
Mysqlx_rows_sent    0
Mysqlx_sessions 0
Mysqlx_sessions_accepted    0
Mysqlx_sessions_closed  0
Mysqlx_sessions_fatal_error 0
Mysqlx_sessions_killed  0
Mysqlx_sessions_rejected    0
Mysqlx_socket   /var/run/mysqld/mysqlx.sock
Mysqlx_ssl_accepts  0
Mysqlx_ssl_active   
Mysqlx_ssl_cipher   
Mysqlx_ssl_cipher_list  
Mysqlx_ssl_ctx_verify_depth 18446744073709551615
Mysqlx_ssl_ctx_verify_mode  5
Mysqlx_ssl_finished_accepts 0
Mysqlx_ssl_server_not_after Mar 15 11:06:01 2029 GMT
Mysqlx_ssl_server_not_before    Mar 18 11:06:01 2019 GMT
Mysqlx_ssl_verify_depth 
Mysqlx_ssl_verify_mode  
Mysqlx_ssl_version  
Mysqlx_stmt_create_collection   0
Mysqlx_stmt_create_collection_index 0
Mysqlx_stmt_disable_notices 0
Mysqlx_stmt_drop_collection 0
Mysqlx_stmt_drop_collection_index   0
Mysqlx_stmt_enable_notices  0
Mysqlx_stmt_ensure_collection   0
Mysqlx_stmt_execute_mysqlx  0
Mysqlx_stmt_execute_sql 0
Mysqlx_stmt_execute_xplugin 0
Mysqlx_stmt_get_collection_options  0
Mysqlx_stmt_kill_client 0
Mysqlx_stmt_list_clients    0
Mysqlx_stmt_list_notices    0
Mysqlx_stmt_list_objects    0
Mysqlx_stmt_modify_collection_options   0
Mysqlx_stmt_ping    0
Mysqlx_worker_threads   2
Mysqlx_worker_threads_active    0
Not_flushed_delayed_rows    0
Ongoing_anonymous_transaction_count 0
Open_files  29
Open_streams    0
Open_table_definitions  404
Open_tables 2372
Opened_files    29
Opened_table_definitions    3101
Opened_tables   726449
Performance_schema_accounts_lost    0
Performance_schema_cond_classes_lost    0
Performance_schema_cond_instances_lost  0
Performance_schema_digest_lost  0
Performance_schema_file_classes_lost    0
Performance_schema_file_handles_lost    0
Performance_schema_file_instances_lost  0
Performance_schema_hosts_lost   0
Performance_schema_index_stat_lost  0
Performance_schema_locker_lost  0
Performance_schema_memory_classes_lost  0
Performance_schema_metadata_lock_lost   0
Performance_schema_mutex_classes_lost   0
Performance_schema_mutex_instances_lost 0
Performance_schema_nested_statement_lost    0
Performance_schema_prepared_statements_lost 0
Performance_schema_program_lost 0
Performance_schema_rwlock_classes_lost  0
Performance_schema_rwlock_instances_lost    0
Performance_schema_session_connect_attrs_longest_seen   243
Performance_schema_session_connect_attrs_lost   0
Performance_schema_socket_classes_lost  0
Performance_schema_socket_instances_lost    0
Performance_schema_stage_classes_lost   0
Performance_schema_statement_classes_lost   0
Performance_schema_table_handles_lost   0
Performance_schema_table_instances_lost 0
Performance_schema_table_lock_stat_lost 0
Performance_schema_thread_classes_lost  0
Performance_schema_thread_instances_lost    0
Performance_schema_users_lost   0
Prepared_stmt_count 0
Queries 50237431
Questions   7738327
Rsa_public_key  -----BEGIN PUBLIC KEY-----
 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0efP6d9Ql944lyxK92xc
 AzZShd/wqacl5NWnwc8eFCmxagEg9iCexoxVJBHQUQrVDZpTuD80/2NEgzrqbf6n
 bVVOB2mVm58NPARTmXC0dJsuaTzBke0KHeNYbrgFr9DoE0IP4Lg2E9c6HQKvSAn9
 LHQ25q+I5Kf+uNlID9RZ+AIvE3UrbeOx...
Secondary_engine_execution_count    0
Select_full_join    82036
Select_full_range_join  33
Select_range    641808
Select_range_check  8
Select_scan 517840
Slave_open_temp_tables  0
Slow_launch_threads 0
Slow_queries    305397
Sort_merge_passes   647
Sort_range  0
Sort_rows   4350778
Sort_scan   199238
Ssl_accept_renegotiates 0
Ssl_accepts 2016
Ssl_callback_cache_hits 0
Ssl_cipher  TLS_AES_256_GCM_SHA384
Ssl_cipher_list TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-A...
Ssl_client_connects 0
Ssl_connect_renegotiates    0
Ssl_ctx_verify_depth    18446744073709551615
Ssl_ctx_verify_mode 5
Ssl_default_timeout 7200
Ssl_finished_accepts    2016
Ssl_finished_connects   0
Ssl_server_not_after    Mar 15 11:06:01 2029 GMT
Ssl_server_not_before   Mar 18 11:06:01 2019 GMT
Ssl_session_cache_hits  0
Ssl_session_cache_misses    0
Ssl_session_cache_mode  SERVER
Ssl_session_cache_overflows 0
Ssl_session_cache_size  128
Ssl_session_cache_timeouts  0
Ssl_sessions_reused 0
Ssl_used_session_cache_entries  0
Ssl_verify_depth    18446744073709551615
Ssl_verify_mode 5
Ssl_version TLSv1.3
Table_locks_immediate   12516
Table_locks_waited  0
Table_open_cache_hits   10773239
Table_open_cache_misses 726449
Table_open_cache_overflows  718062
Tc_log_max_pages_used   0
Tc_log_page_size    0
Tc_log_page_waits   0
Threads_cached  4
Threads_connected   47
Threads_created 87
Threads_running 2
Uptime  96942
Uptime_since_flush_status   96942

过去 30 天的 tmp 表和内存

标签: mysql

解决方案


从您的 SHOW GLOBAL STATUS 数据来看,threads_connected 在 2 天后为 48 表明 'CONNECT'、'PROCESS'、'CLOSE' 周期可能缺少典型处理的 CLOSE。

两分钟的常规日志应包括正常操作中的一些“退出”行。

我的个人资料有联系信息。

建议,使用 32G 中的 20G 可用于 innodb_buffer_pool_size 将显着降低 innodb_buffer_pool_reads Rate Per Hr 12,976。对 innodb_lru_scan_depth 使用 100 将节省大约 90% 的 CPU 周期用于该函数每 SECOND。


推荐阅读