Mysql used all memory - mysql

Summary:
My MySql after a few days of operation consumes all memory and crash by
Software versions:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Linux 4.15.0-147-generic
Server version: 8.0.24 MySQL Community Server
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
The values are set so that Max MySQL memory is 11.3G. Total buffers: 6.0G global + 33.9M per thread (160 max threads). The server has 32GB RAM and only runs 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
UPDATE:
This is valuve when mysql used 22GB ram what is two time mor then max MySQL memory with value 11GB.
HTOP SCREEN
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
tmp tables and memoty last 30 days

From your SHOW GLOBAL STATUS data, threads_connected at 48 after 2 days is an indicator the 'CONNECT','PROCESS','CLOSE' cycle may be missing the CLOSE of typical processing.
A two minute General Log should include some 'QUIT' lines in normal operation.
My profile has contact info.
Suggestion, using 20G of your 32G available for your innodb_buffer_pool_size would significantly reduce your innodb_buffer_pool_reads Rate Per Hr of 12,976. Using 100 for innodb_lru_scan_depth would conserve about 90% of CPU cycles used for the function every SECOND.

Related

MySQL 5.5 innoDB writes drop, scripts slow down and locks increase

I have a database that I do INSERTS into by a python script that calls various API's and runs on a cron. There are also SELECT statements that look at previous values in the table in order to create averages based off the current and previous data.
Everything runs fine for a day or two, however after that the database seems to enter a form of contention where the sites will drop, locks will increase and the scripts slow down in their performance. I do deletes after all scripts complete (Never at the same time to avoid locking) in order to truncate data and keep the database small ensuring it doesn't reach it's buffer_pool_size limit.
Previously I had a crazy query_cache_size of 2048M for a DB that is heavy on writes, I've changed that to 10M recently and the query_cache_limit to 256K since then I've done no extra changes.
There are a lot of mixed reviews online about what can be done to optimise this, most of my tables have an index because it is also heavy on SELECT statements as well as writes.
The below is my my.cnf file, I'm hoping someone might be able to help with if there's any setting here that might be ubsurd and should be changed. I'm running on mysql Ver 14.14 Distrib 5.5.62, for debian-linux-gnu (x86_64) and using innoDB. Below is the my.cnf file. Appreciate the help.
thread_cache_size was set to 100 as max_used_connections tends to sit on 128. Threads_connected tends to range from 90-120.
The server is a 4-core 32gb RAM server from AWS r5.xlarge
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
host = 127.0.0.1
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/lib/mysql/mysql.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/lib/mysql/mysql.pid #/var/run/mysqld/mysqld.pid
socket = /var/lib/mysql/mysql.sock #/var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
key_buffer_size = 256M
table_cache = 16394
thread_cache_size = 100
innodb_file_per_table = ON
## Per-Thread Buffers * (max_connections) = total per-thread mem usage
thread_stack = 256K #default: 32bit: 192K, 64bit: 256K
sort_buffer_size = 2M #default: 2M, larger may cause perf issues
read_buffer_size = 2M #default: 128K, change in increments of 4K
read_rnd_buffer_size = 2M #default: 256K
join_buffer_size = 2M #default: 128K
binlog_cache_size = 256K #default: 32K, size of buffer to hold TX queries
## Query Cache
query_cache_size = 10M #global buffer
query_cache_limit = 256K #max query result size to put in cache
## Connections
max_connections = 500 # was 400 #multiplier for memory usage via per-thread buffers
max_connect_errors = 100 # was 200 #default: 10
concurrent_insert = 2 #default: 1, 2: enable insert for all instances
connect_timeout = 60 #default -5.1.22: 5, +5.1.22: 10
## Table and TMP settings
max_heap_table_size = 2048M #recommend same size as tmp_table_size
bulk_insert_buffer_size = 2048M #recommend same size as tmp_table_size
tmp_table_size = 2048M #recommend 1G min
## MyISAM Engine
key_buffer = 2M #global buffer
myisam_sort_buffer_size = 256M #index buffer size for creating/altering indexes
myisam_max_sort_file_size = 512M #max file size for tmp table when creating/alering indexes
## InnoDB IO settings - 5.5.x and greater
innodb_write_io_threads = 64 # Apr7
innodb_read_io_threads = 64 # Apr7
#innodb_log_file_size = 3G
innodb_buffer_pool_size = 22G #global buffer
innodb-buffer-pool-instances = 20
innodb_additional_mem_pool_size = 24M #global buffer
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
Complete GLOBAL STATUS after the servers been up for over 24 hours and has now hit the contention state.
Variable_name Value
Aborted_clients 8659
Aborted_connects 0
Binlog_cache_disk_use 0
Binlog_cache_use 0
Binlog_stmt_cache_disk_use 0
Binlog_stmt_cache_use 0
Bytes_received 10528823106
Bytes_sent 11879095113
Com_admin_commands 114321
Com_assign_to_keycache 0
Com_alter_db 0
Com_alter_db_upgrade 0
Com_alter_event 0
Com_alter_function 0
Com_alter_procedure 0
Com_alter_server 0
Com_alter_table 0
Com_alter_tablespace 0
Com_analyze 0
Com_begin 0
Com_binlog 0
Com_call_procedure 0
Com_change_db 2494
Com_change_master 0
Com_check 0
Com_checksum 0
Com_commit 21669803
Com_create_db 0
Com_create_event 0
Com_create_function 0
Com_create_index 0
Com_create_procedure 0
Com_create_server 0
Com_create_table 0
Com_create_trigger 0
Com_create_udf 0
Com_create_user 0
Com_create_view 0
Com_dealloc_sql 0
Com_delete 57847
Com_delete_multi 2
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_server 0
Com_drop_table 0
Com_drop_trigger 0
Com_drop_user 0
Com_drop_view 0
Com_empty_query 0
Com_execute_sql 0
Com_flush 1
Com_grant 0
Com_ha_close 0
Com_ha_open 0
Com_ha_read 0
Com_help 0
Com_insert 10384315
Com_insert_select 4493
Com_install_plugin 0
Com_kill 0
Com_load 0
Com_lock_tables 0
Com_optimize 0
Com_preload_keys 0
Com_prepare_sql 0
Com_purge 0
Com_purge_before_date 0
Com_release_savepoint 0
Com_rename_table 0
Com_rename_user 0
Com_repair 0
Com_replace 0
Com_replace_select 0
Com_reset 0
Com_resignal 0
Com_revoke 0
Com_revoke_all 0
Com_rollback 0
Com_rollback_to_savepoint 0
Com_savepoint 0
Com_select 31617317
Com_set_option 585637
Com_signal 0
Com_show_authors 0
Com_show_binlog_events 0
Com_show_binlogs 0
Com_show_charsets 0
Com_show_collations 0
Com_show_contributors 0
Com_show_create_db 0
Com_show_create_event 0
Com_show_create_func 0
Com_show_create_proc 0
Com_show_create_table 0
Com_show_create_trigger 0
Com_show_databases 1
Com_show_engine_logs 0
Com_show_engine_mutex 0
Com_show_engine_status 4415
Com_show_events 0
Com_show_errors 0
Com_show_fields 7780
Com_show_function_status 0
Com_show_grants 0
Com_show_keys 0
Com_show_master_status 0
Com_show_open_tables 0
Com_show_plugins 0
Com_show_privileges 0
Com_show_procedure_status 0
Com_show_processlist 0
Com_show_profile 0
Com_show_profiles 0
Com_show_relaylog_events 0
Com_show_slave_hosts 0
Com_show_slave_status 0
Com_show_status 4416
Com_show_storage_engines 0
Com_show_table_status 0
Com_show_tables 2492
Com_show_triggers 0
Com_show_variables 9040
Com_show_warnings 11880457
Com_slave_start 0
Com_slave_stop 0
Com_stmt_close 48226
Com_stmt_execute 90467
Com_stmt_fetch 0
Com_stmt_prepare 48354
Com_stmt_reprepare 0
Com_stmt_reset 0
Com_stmt_send_long_data 218
Com_truncate 16
Com_uninstall_plugin 0
Com_unlock_tables 0
Com_update 11304832
Com_update_multi 0
Com_xa_commit 0
Com_xa_end 0
Com_xa_prepare 0
Com_xa_recover 0
Com_xa_rollback 0
Com_xa_start 0
Compression ON
Connections 692888
Created_tmp_disk_tables 969524
Created_tmp_files 152
Created_tmp_tables 1104523
Delayed_errors 0
Delayed_insert_threads 0
Delayed_writes 0
Flush_commands 1
Handler_commit 74944534
Handler_delete 9802964
Handler_discover 0
Handler_prepare 0
Handler_read_first 333333
Handler_read_key 61866586
Handler_read_last 3454093
Handler_read_next 13704879326
Handler_read_prev 2773935641
Handler_read_rnd 39932346
Handler_read_rnd_next 9899032663
Handler_rollback 170160
Handler_savepoint 0
Handler_savepoint_rollback 0
Handler_update 40464627
Handler_write 180607735
Innodb_buffer_pool_pages_data 768282
Innodb_buffer_pool_bytes_data 12587532288
Innodb_buffer_pool_pages_dirty 10741
Innodb_buffer_pool_bytes_dirty 175980544
Innodb_buffer_pool_pages_flushed 39908997
Innodb_buffer_pool_pages_free 563241
Innodb_buffer_pool_pages_misc 110237
Innodb_buffer_pool_pages_total 1441760
Innodb_buffer_pool_read_ahead_rnd 0
Innodb_buffer_pool_read_ahead 24195
Innodb_buffer_pool_read_ahead_evicted 0
Innodb_buffer_pool_read_requests 61256179019
Innodb_buffer_pool_reads 519946
Innodb_buffer_pool_wait_free 0
Innodb_buffer_pool_write_requests 307699280
Innodb_data_fsyncs 22277830
Innodb_data_pending_fsyncs 1
Innodb_data_pending_reads 0
Innodb_data_pending_writes 0
Innodb_data_read 10761654272
Innodb_data_reads 656718
Innodb_data_writes 59599294
Innodb_data_written 1327119237120
Innodb_dblwr_pages_written 39909506
Innodb_dblwr_writes 2757000
Innodb_have_atomic_builtins ON
Innodb_log_waits 0
Innodb_log_write_requests 22935831
Innodb_log_writes 16721934
Innodb_os_log_fsyncs 16783015
Innodb_os_log_pending_fsyncs 1
Innodb_os_log_pending_writes 0
Innodb_os_log_written 19349207552
Innodb_page_size 16384
Innodb_pages_created 111573
Innodb_pages_read 656709
Innodb_pages_written 39909506
Innodb_row_lock_current_waits 0
Innodb_row_lock_time 78010
Innodb_row_lock_time_avg 84
Innodb_row_lock_time_max 3217
Innodb_row_lock_waits 926
Innodb_rows_deleted 9802964
Innodb_rows_inserted 10494572
Innodb_rows_read 25829527401
Innodb_rows_updated 13355863
Innodb_truncated_status_writes 0
Key_blocks_not_flushed 0
Key_blocks_unused 1674
Key_blocks_used 21
Key_read_requests 358190032
Key_reads 0
Key_write_requests 116148559
Key_writes 0
Last_query_cost 0.000000
Max_used_connections 247
Not_flushed_delayed_rows 0
Open_files 48
Open_streams 0
Open_table_definitions 325
Open_tables 597
Opened_files 3878714
Opened_table_definitions 341
Opened_tables 620
Performance_schema_cond_classes_lost 0
Performance_schema_cond_instances_lost 0
Performance_schema_file_classes_lost 0
Performance_schema_file_handles_lost 0
Performance_schema_file_instances_lost 0
Performance_schema_locker_lost 0
Performance_schema_mutex_classes_lost 0
Performance_schema_mutex_instances_lost 0
Performance_schema_rwlock_classes_lost 0
Performance_schema_rwlock_instances_lost 0
Performance_schema_table_handles_lost 0
Performance_schema_table_instances_lost 0
Performance_schema_thread_classes_lost 0
Performance_schema_thread_instances_lost 0
Prepared_stmt_count 128
Qcache_free_blocks 0
Qcache_free_memory 0
Qcache_hits 0
Qcache_inserts 0
Qcache_lowmem_prunes 0
Qcache_not_cached 0
Qcache_queries_in_cache 0
Qcache_total_blocks 0
Queries 88430604
Questions 88219702
Rpl_status AUTH_MASTER
Select_full_join 3100
Select_full_range_join 806
Select_range 14288643
Select_range_check 0
Select_scan 225040
Slave_heartbeat_period 0.000
Slave_open_temp_tables 0
Slave_received_heartbeats 0
Slave_retried_transactions 0
Slave_running OFF
Slow_launch_threads 0
Slow_queries 18
Sort_merge_passes 147
Sort_range 7993917
Sort_rows 23603619
Sort_scan 934553
Ssl_accept_renegotiates 0
Ssl_accepts 0
Ssl_callback_cache_hits 0
Ssl_cipher
Ssl_cipher_list
Ssl_client_connects 0
Ssl_connect_renegotiates 0
Ssl_ctx_verify_depth 0
Ssl_ctx_verify_mode 0
Ssl_default_timeout 0
Ssl_finished_accepts 0
Ssl_finished_connects 0
Ssl_session_cache_hits 0
Ssl_session_cache_misses 0
Ssl_session_cache_mode NONE
Ssl_session_cache_overflows 0
Ssl_session_cache_size 0
Ssl_session_cache_timeouts 0
Ssl_sessions_reused 0
Ssl_used_session_cache_entries 0
Ssl_verify_depth 0
Ssl_verify_mode 0
Ssl_version
Table_locks_immediate 67102620
Table_locks_waited 0
Tc_log_max_pages_used 0
Tc_log_page_size 0
Tc_log_page_waits 0
Threads_cached 58
Threads_connected 102
Threads_created 674
Threads_running 5
Uptime 84415
Uptime_since_flush_status 84415

Mysql memory usage growing until OOM and system kills / restarts

I have MySQL 5.7.27 under Ubuntu 16.04.4, 64 bit, 4GB RAM and SSDs (it's a virtual machine). I am observing resident memory growth in mysqld until no more resources are available and the OS kills / restarts mysqld.
Some background - The system is used to collect information from remote locations, with 1 entity being collected from each location. Each entity might have many hundreds of data points. For each remote location, there are two databases, which supports two situations: each location is per customer (but one customer might have many - thousands - of such locations) and in some situations, it might be many thousands of entities being collected from each remote location. The two DBs correspond to raw data collected and "processed" summaries. In addition, there is one additional DB per customer recording admin and other data about each remote location. So, total DB count is C * ( 1 + 2L ) - C for customer, L for location. The first DB of 2L has 32 tables and a minimum size of 2MB (but I have at least one example which it 5.9GB - not in this current sample set) - it is "cleared" at the start of each collection event; the second has 12 tables and typical size in the current sample set is 1MB (although this accumulates for each collection event).
A remote collection is performed periodically, say once a week or once a month, per remote location. After each collection, a process is run to summarise data from the ALL of the 2L databases into the one unifying one.
In the system with the issue, there are C ( 1 + 2L ) equaling just over 5000. When the summarisation process is run, mysqld resident memory (viewed using top) grows from around 800MB to just under 3GB. The summarisation process completes and might then run again a short time afterwards. That process completes cleanly and correctly releases query results and closes DB connections. The application is PHP 7.2.24 CLI running locally (so, using sockets, not TCP).
I have tried "tuning":
open_files_limit = 11000
table_open_cache = 5200
innodb_lru_scan_depth = 128
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size = 1073741824
(see open_files_limit, table_open_cache, innodb_lru_scan_depth, innodb_flush_log_at_trx_commit, innodb_buffer_pool_size)
These either made no apparent change or worsened the rate of growth of memory usage. I also ran show engine performance_schema status; at three instances: when resident memory was at 2459MB, 2478MB and 2910MB. Between those three samples, I saw differences only in the following metrics:
2459MB 2478MB 2910MB
(digest_hash).count 4676 -> 4837 -> 4958
(filename_hash).count 121118 -> 121139 -> 121214
(table_share_hash).count 27229 -> 27247 -> 27276
mutex_instances.count 29696 -> 30720 -> 31744
mutex_instances.memory 3801088 -> 3932160 -> 4063232
performance_scheme.memory 426293432 -> 426424504 -> 4266886648
rwlock_instances.count 400384 -> 400384 -> 401408
rwlock_instances.memory 51249152 -> 51249152 -> 51380224
My expectation is that at the end of each summarisation run, either "temporary" buffer space in mysqld would be freed up, or would simply be reused at the next run of that process, given that it effectively is making the same sequence of queries (and very similar updates) across the same set of databases / tables. The fact that the memory footprint grows suggest to me that either there is a memory leak in mysqld, or that an intentional "buffer" related to some failure condition (connections, locks, mutexes?) is at least part of the cause of the memory growth. I suggest the latter, because I would look at what would persist in mysqld between subsequent runs of that summarisation process.
I have also tried running mysqltuner.pl (see http://mysqltuner.com), but this also causes the memory growth problem, which is undoubtedly related to the number of databases. However, if I might refer to https://dev.mysql.com/doc/refman/5.7/en/database-count-limit.html, whatever limit MySQL might or might not have to the number of databases and tables, the numbers here are not significant to mysqld itself, even if they might be to the underlying OS. I confess I was impressed that the server was apparently handling over 1000 SELECTS per second on a not very highly spec'd system.
So, What "monitoring" parameters should I be looking at to assist with tuning mysql, the OS or platform and what (mysql / OS) tuning parameters would be most helpful in this situation? I could just take the Jaws approach ("We're going to need a bigger boat"), but if the issue I'm experiencing is a memory leak, then just adding more RAM is only just postponing the inevitable.
------------ EDIT following answer by Rick James (2020/01/13) -
RAM - 4GB
SHOW VARIABLES; (less SSL related info) output:
auto_generate_certs ON
auto_increment_increment 1
auto_increment_offset 1
autocommit ON
automatic_sp_privileges ON
avoid_temporal_upgrade OFF
back_log 80
basedir /usr/
big_tables OFF
bind_address *
binlog_cache_size 32768
binlog_checksum CRC32
binlog_direct_non_transactional_updates OFF
binlog_error_action ABORT_SERVER
binlog_format ROW
binlog_group_commit_sync_delay 0
binlog_group_commit_sync_no_delay_count 0
binlog_gtid_simple_recovery ON
binlog_max_flush_queue_time 0
binlog_order_commits ON
binlog_row_image FULL
binlog_rows_query_log_events OFF
binlog_stmt_cache_size 32768
binlog_transaction_dependency_history_size 25000
binlog_transaction_dependency_tracking COMMIT_ORDER
block_encryption_mode aes-128-ecb
bulk_insert_buffer_size 8388608
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8
character_set_filesystem binary
character_set_results utf8mb4
character_set_server utf8
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
check_proxy_users OFF
collation_connection utf8mb4_general_ci
collation_database utf8_unicode_ci
collation_server utf8_unicode_ci
completion_type NO_CHAIN
concurrent_insert AUTO
connect_timeout 10
core_file OFF
datadir /var/lib/mysql/
date_format %Y-%m-%d
datetime_format %Y-%m-%d %H:%i:%s
default_authentication_plugin mysql_native_password
default_password_lifetime 0
default_storage_engine InnoDB
default_tmp_storage_engine InnoDB
default_week_format 0
delay_key_write ON
delayed_insert_limit 100
delayed_insert_timeout 300
delayed_queue_size 1000
disabled_storage_engines
disconnect_on_expired_password ON
div_precision_increment 4
end_markers_in_json OFF
enforce_gtid_consistency OFF
eq_range_index_dive_limit 200
error_count 0
event_scheduler OFF
expire_logs_days 10
explicit_defaults_for_timestamp OFF
external_user
flush OFF
flush_time 0
foreign_key_checks ON
ft_boolean_syntax + -><()~*:""&|
ft_max_word_len 84
ft_min_word_len 4
ft_query_expansion_limit 20
ft_stopword_file (built-in)
general_log OFF
general_log_file /var/lib/mysql/demo.log
group_concat_max_len 1024
gtid_executed_compression_period 1000
gtid_mode OFF
gtid_next AUTOMATIC
gtid_owned
gtid_purged
have_compress YES
have_crypt YES
have_dynamic_loading YES
have_geometry YES
have_openssl YES
have_profiling YES
have_query_cache YES
have_rtree_keys YES
have_ssl YES
have_statement_timeout YES
have_symlink YES
host_cache_size 279
hostname <hidden>
identity 0
ignore_builtin_innodb OFF
ignore_db_dirs
init_connect
init_file
init_slave
innodb_adaptive_flushing ON
innodb_adaptive_flushing_lwm 10
innodb_adaptive_hash_index ON
innodb_adaptive_hash_index_parts 8
innodb_adaptive_max_sleep_delay 150000
innodb_api_bk_commit_interval 5
innodb_api_disable_rowlock OFF
innodb_api_enable_binlog OFF
innodb_api_enable_mdl OFF
innodb_api_trx_level 0
innodb_autoextend_increment 64
innodb_autoinc_lock_mode 1
innodb_buffer_pool_chunk_size 134217728
innodb_buffer_pool_dump_at_shutdown ON
innodb_buffer_pool_dump_now OFF
innodb_buffer_pool_dump_pct 25
innodb_buffer_pool_filename ib_buffer_pool
innodb_buffer_pool_instances 1
innodb_buffer_pool_load_abort OFF
innodb_buffer_pool_load_at_startup ON
innodb_buffer_pool_load_now OFF
innodb_buffer_pool_size 134217728
innodb_change_buffer_max_size 25
innodb_change_buffering all
innodb_checksum_algorithm crc32
innodb_checksums ON
innodb_cmp_per_index_enabled OFF
innodb_commit_concurrency 0
innodb_compression_failure_threshold_pct 5
innodb_compression_level 6
innodb_compression_pad_pct_max 50
innodb_concurrency_tickets 5000
innodb_data_file_path ibdata1:12M:autoextend
innodb_data_home_dir
innodb_deadlock_detect ON
innodb_default_row_format dynamic
innodb_disable_sort_file_cache OFF
innodb_doublewrite ON
innodb_fast_shutdown 1
innodb_file_format Barracuda
innodb_file_format_check ON
innodb_file_format_max Barracuda
innodb_file_per_table ON
innodb_fill_factor 100
innodb_flush_log_at_timeout 1
innodb_flush_log_at_trx_commit 2
innodb_flush_method
innodb_flush_neighbors 1
innodb_flush_sync ON
innodb_flushing_avg_loops 30
innodb_force_load_corrupted OFF
innodb_force_recovery 0
innodb_ft_aux_table
innodb_ft_cache_size 8000000
innodb_ft_enable_diag_print OFF
innodb_ft_enable_stopword ON
innodb_ft_max_token_size 84
innodb_ft_min_token_size 3
innodb_ft_num_word_optimize 2000
innodb_ft_result_cache_limit 2000000000
innodb_ft_server_stopword_table
innodb_ft_sort_pll_degree 2
innodb_ft_total_cache_size 640000000
innodb_ft_user_stopword_table
innodb_io_capacity 200
innodb_io_capacity_max 2000
innodb_large_prefix ON
innodb_lock_wait_timeout 50
innodb_locks_unsafe_for_binlog OFF
innodb_log_buffer_size 16777216
innodb_log_checksums ON
innodb_log_compressed_pages ON
innodb_log_file_size 50331648
innodb_log_files_in_group 2
innodb_log_group_home_dir ./
innodb_log_write_ahead_size 8192
innodb_lru_scan_depth 128
innodb_max_dirty_pages_pct 75
innodb_max_dirty_pages_pct_lwm 0
innodb_max_purge_lag 0
innodb_max_purge_lag_delay 0
innodb_max_undo_log_size 1073741824
innodb_monitor_disable
innodb_monitor_enable
innodb_monitor_reset
innodb_monitor_reset_all
innodb_numa_interleave OFF
innodb_old_blocks_pct 37
innodb_old_blocks_time 1000
innodb_online_alter_log_max_size 134217728
innodb_open_files 5200
innodb_optimize_fulltext_only OFF
innodb_page_cleaners 1
innodb_page_size 16384
innodb_print_all_deadlocks OFF
innodb_purge_batch_size 300
innodb_purge_rseg_truncate_frequency 128
innodb_purge_threads 4
innodb_random_read_ahead OFF
innodb_read_ahead_threshold 56
innodb_read_io_threads 4
innodb_read_only OFF
innodb_replication_delay 0
innodb_rollback_on_timeout OFF
innodb_rollback_segments 128
innodb_sort_buffer_size 1048576
innodb_spin_wait_delay 6
innodb_stats_auto_recalc ON
innodb_stats_include_delete_marked OFF
innodb_stats_method nulls_equal
innodb_stats_on_metadata OFF
innodb_stats_persistent ON
innodb_stats_persistent_sample_pages 20
innodb_stats_sample_pages 8
innodb_stats_transient_sample_pages 8
innodb_status_output OFF
innodb_status_output_locks OFF
innodb_strict_mode ON
innodb_support_xa ON
innodb_sync_array_size 1
innodb_sync_spin_loops 30
innodb_table_locks ON
innodb_temp_data_file_path ibtmp1:12M:autoextend
innodb_thread_concurrency 0
innodb_thread_sleep_delay 10000
innodb_tmpdir
innodb_undo_directory ./
innodb_undo_log_truncate OFF
innodb_undo_logs 128
innodb_undo_tablespaces 0
innodb_use_native_aio ON
innodb_version 5.7.28
innodb_write_io_threads 4
insert_id 0
interactive_timeout 28800
internal_tmp_disk_storage_engine InnoDB
join_buffer_size 262144
keep_files_on_create OFF
key_buffer_size 16777216
key_cache_age_threshold 300
key_cache_block_size 1024
key_cache_division_limit 100
keyring_operations ON
large_files_support ON
large_page_size 0
large_pages OFF
last_insert_id 0
lc_messages en_US
lc_messages_dir /usr/share/mysql/
lc_time_names en_US
license GPL
local_infile ON
lock_wait_timeout 31536000
locked_in_memory OFF
log_bin OFF
log_bin_basename
log_bin_index
log_bin_trust_function_creators OFF
log_bin_use_v1_row_events OFF
log_builtin_as_identified_by_password OFF
log_error /var/log/mysql/error.log
log_error_verbosity 3
log_output FILE
log_queries_not_using_indexes OFF
log_slave_updates OFF
log_slow_admin_statements OFF
log_slow_slave_statements OFF
log_statements_unsafe_for_binlog ON
log_syslog OFF
log_syslog_facility daemon
log_syslog_include_pid ON
log_syslog_tag
log_throttle_queries_not_using_indexes 0
log_timestamps UTC
log_warnings 2
long_query_time 10
low_priority_updates OFF
lower_case_file_system OFF
lower_case_table_names 0
master_info_repository FILE
master_verify_checksum OFF
max_allowed_packet 16777216
max_binlog_cache_size 1.84467440737095E+019
max_binlog_size 104857600
max_binlog_stmt_cache_size 1.84467440737095E+019
max_connect_errors 100
max_connections 151
max_delayed_threads 20
max_digest_length 1024
max_error_count 64
max_execution_time 0
max_heap_table_size 16777216
max_insert_delayed_threads 20
max_join_size 1.84467440737096E+019
max_length_for_sort_data 1024
max_points_in_geometry 65536
max_prepared_stmt_count 16382
max_relay_log_size 0
max_seeks_for_key 1.84467440737096E+019
max_sort_length 1024
max_sp_recursion_depth 0
max_tmp_tables 32
max_user_connections 0
max_write_lock_count 1.84467440737096E+019
metadata_locks_cache_size 1024
metadata_locks_hash_instances 8
min_examined_row_limit 0
multi_range_count 256
myisam_data_pointer_size 6
myisam_max_sort_file_size 9.22337203685373E+018
myisam_mmap_size 1.84467440737096E+019
myisam_recover_options BACKUP
myisam_repair_threads 1
myisam_sort_buffer_size 8388608
myisam_stats_method nulls_unequal
myisam_use_mmap OFF
mysql_native_password_proxy_users OFF
net_buffer_length 16384
net_read_timeout 30
net_retry_count 10
net_write_timeout 60
new OFF
ngram_token_size 2
offline_mode OFF
old OFF
old_alter_table OFF
old_passwords 0
open_files_limit 11000
optimizer_prune_level 1
optimizer_search_depth 62
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on
optimizer_trace enabled=off,one_line=off
optimizer_trace_features greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
optimizer_trace_limit 1
optimizer_trace_max_mem_size 16384
optimizer_trace_offset -1
parser_max_mem_size 1.84467440737096E+019
performance_schema ON
performance_schema_accounts_size -1
performance_schema_digests_size 10000
performance_schema_events_stages_history_long_size 10000
performance_schema_events_stages_history_size 10
performance_schema_events_statements_history_long_size 10000
performance_schema_events_statements_history_size 10
performance_schema_events_transactions_history_long_size 10000
performance_schema_events_transactions_history_size 10
performance_schema_events_waits_history_long_size 10000
performance_schema_events_waits_history_size 10
performance_schema_hosts_size -1
performance_schema_max_cond_classes 80
performance_schema_max_cond_instances -1
performance_schema_max_digest_length 1024
performance_schema_max_file_classes 80
performance_schema_max_file_handles 32768
performance_schema_max_file_instances -1
performance_schema_max_index_stat -1
performance_schema_max_memory_classes 320
performance_schema_max_metadata_locks -1
performance_schema_max_mutex_classes 210
performance_schema_max_mutex_instances -1
performance_schema_max_prepared_statements_instances -1
performance_schema_max_program_instances -1
performance_schema_max_rwlock_classes 50
performance_schema_max_rwlock_instances -1
performance_schema_max_socket_classes 10
performance_schema_max_socket_instances -1
performance_schema_max_sql_text_length 1024
performance_schema_max_stage_classes 150
performance_schema_max_statement_classes 193
performance_schema_max_statement_stack 10
performance_schema_max_table_handles -1
performance_schema_max_table_instances -1
performance_schema_max_table_lock_stat -1
performance_schema_max_thread_classes 50
performance_schema_max_thread_instances -1
performance_schema_session_connect_attrs_size 512
performance_schema_setup_actors_size -1
performance_schema_setup_objects_size -1
performance_schema_users_size -1
pid_file /var/run/mysqld/mysqld.pid
plugin_dir /usr/lib/mysql/plugin/
port 3306
preload_buffer_size 32768
profiling OFF
profiling_history_size 15
protocol_version 10
proxy_user
pseudo_slave_mode OFF
pseudo_thread_id 8224
query_alloc_block_size 8192
query_cache_limit 1048576
query_cache_min_res_unit 4096
query_cache_size 16777216
query_cache_type OFF
query_cache_wlock_invalidate OFF
query_prealloc_size 8192
rand_seed1 0
rand_seed2 0
range_alloc_block_size 4096
range_optimizer_max_mem_size 8388608
rbr_exec_mode STRICT
read_buffer_size 131072
read_only OFF
read_rnd_buffer_size 262144
relay_log
relay_log_basename /var/lib/mysql/demo-relay-bin
relay_log_index /var/lib/mysql/demo-relay-bin.index
relay_log_info_file relay-log.info
relay_log_info_repository FILE
relay_log_purge ON
relay_log_recovery OFF
relay_log_space_limit 0
report_host
report_password
report_port 3306
report_user
require_secure_transport ON
rpl_stop_slave_timeout 31536000
secure_auth ON
secure_file_priv /var/lib/mysql-files/
server_id 0
server_id_bits 32
server_uuid <hidden>
session_track_gtids OFF
session_track_schema ON
session_track_state_change OFF
session_track_system_variables time_zone,autocommit,character_set_client,character_set_results,character_set_connection
session_track_transaction_info OFF
sha256_password_auto_generate_rsa_keys ON
sha256_password_private_key_path private_key.pem
sha256_password_proxy_users OFF
sha256_password_public_key_path public_key.pem
show_compatibility_56 OFF
show_create_table_verbosity OFF
show_old_temporals OFF
skip_external_locking ON
skip_name_resolve OFF
skip_networking OFF
skip_show_database OFF
slave_allow_batching OFF
slave_checkpoint_group 512
slave_checkpoint_period 300
slave_compressed_protocol OFF
slave_exec_mode STRICT
slave_load_tmpdir /tmp
slave_max_allowed_packet 1073741824
slave_net_timeout 60
slave_parallel_type DATABASE
slave_parallel_workers 0
slave_pending_jobs_size_max 16777216
slave_preserve_commit_order OFF
slave_rows_search_algorithms TABLE_SCAN,INDEX_SCAN
slave_skip_errors OFF
slave_sql_verify_checksum ON
slave_transaction_retries 10
slave_type_conversions
slow_launch_time 2
slow_query_log OFF
slow_query_log_file /var/lib/mysql/demo-slow.log
socket /var/run/mysqld/mysqld.sock
sort_buffer_size 262144
sql_auto_is_null OFF
sql_big_selects ON
sql_buffer_result OFF
sql_log_bin ON
sql_log_off OFF
sql_mode ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_notes ON
sql_quote_show_create ON
sql_safe_updates OFF
sql_select_limit 1.84467440737096E+019
sql_slave_skip_counter 0
sql_warnings OFF
stored_program_cache 256
super_read_only OFF
sync_binlog 1
sync_frm ON
sync_master_info 10000
sync_relay_log 10000
sync_relay_log_info 10000
system_time_zone GMT
table_definition_cache 2000
table_open_cache 5200
table_open_cache_instances 16
thread_cache_size 8
thread_handling one-thread-per-connection
thread_stack 262144
time_format %H:%i:%s
time_zone SYSTEM
timestamp 1579095336.07864
tls_version TLSv1,TLSv1.1,TLSv1.2
tmp_table_size 16777216
tmpdir /tmp
transaction_alloc_block_size 8192
transaction_allow_batching OFF
transaction_isolation REPEATABLE-READ
transaction_prealloc_size 4096
transaction_read_only OFF
transaction_write_set_extraction OFF
tx_isolation REPEATABLE-READ
tx_read_only OFF
unique_checks ON
updatable_views_with_limit YES
version 5.7.28-0ubuntu0.16.04.2
version_comment (Ubuntu)
version_compile_machine x86_64
version_compile_os Linux
wait_timeout 28800
warning_count 0
SHOW GLOBAL STATUS; (less SSL related info and any com_*=0 values) output:
Aborted_clients 0
Aborted_connects 4
Binlog_cache_disk_use 0
Binlog_cache_use 0
Binlog_stmt_cache_disk_use 0
Binlog_stmt_cache_use 0
Bytes_received 120596117
Bytes_sent 423055987
Com_admin_commands 1422
Com_change_db 1969
Com_delete 26
Com_delete_multi 5
Com_flush 5
Com_insert 543
Com_lock_tables 106103
Com_select 290121
Com_set_option 3952
Com_show_charsets 4
Com_show_fields 1756
Com_show_keys 3
Com_show_plugins 1
Com_show_status 2317
Com_show_tables 4
Com_show_variables 10
Com_unlock_tables 106103
Com_update 119462
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 53918
Created_tmp_disk_tables 7205
Created_tmp_files 6
Created_tmp_tables 26682
Delayed_errors 0
Delayed_insert_threads 0
Delayed_writes 0
Flush_commands 1
Handler_commit 516258
Handler_delete 605
Handler_discover 0
Handler_external_lock 1131715
Handler_mrr_init 0
Handler_prepare 0
Handler_read_first 251891
Handler_read_key 1450835
Handler_read_last 0
Handler_read_next 46912240
Handler_read_prev 0
Handler_read_rnd 333804
Handler_read_rnd_next 77706400
Handler_rollback 0
Handler_savepoint 0
Handler_savepoint_rollback 0
Handler_update 20612
Handler_write 139820
Innodb_buffer_pool_dump_status Dumping of buffer pool not started
Innodb_buffer_pool_load_status Buffer pool(s) load completed at 200110 15:44:11
Innodb_buffer_pool_resize_status
Innodb_buffer_pool_pages_data 7744
Innodb_buffer_pool_bytes_data 126877696
Innodb_buffer_pool_pages_dirty 0
Innodb_buffer_pool_bytes_dirty 0
Innodb_buffer_pool_pages_flushed 10525
Innodb_buffer_pool_pages_free 128
Innodb_buffer_pool_pages_misc 319
Innodb_buffer_pool_pages_total 8191
Innodb_buffer_pool_read_ahead_rnd 0
Innodb_buffer_pool_read_ahead 2174
Innodb_buffer_pool_read_ahead_evicted 552
Innodb_buffer_pool_read_requests 92861248
Innodb_buffer_pool_reads 230500
Innodb_buffer_pool_wait_free 0
Innodb_buffer_pool_write_requests 490867
Innodb_data_fsyncs 6682
Innodb_data_pending_fsyncs 0
Innodb_data_pending_reads 0
Innodb_data_pending_writes 0
Innodb_data_read 3812250112
Innodb_data_reads 257019
Innodb_data_writes 36166
Innodb_data_written 301705728
Innodb_dblwr_pages_written 5776
Innodb_dblwr_writes 1121
Innodb_log_waits 0
Innodb_log_write_requests 24009
Innodb_log_writes 23298
Innodb_os_log_fsyncs 3651
Innodb_os_log_pending_fsyncs 0
Innodb_os_log_pending_writes 0
Innodb_os_log_written 34017280
Innodb_page_size 16384
Innodb_pages_created 388
Innodb_pages_read 232676
Innodb_pages_written 10525
Innodb_row_lock_current_waits 0
Innodb_row_lock_time 0
Innodb_row_lock_time_avg 0
Innodb_row_lock_time_max 0
Innodb_row_lock_waits 0
Innodb_rows_deleted 605
Innodb_rows_inserted 33914
Innodb_rows_read 125144394
Innodb_rows_updated 20612
Innodb_num_open_files 5200
Innodb_truncated_status_writes 0
Innodb_available_undo_logs 128
Key_blocks_not_flushed 0
Key_blocks_unused 13396
Key_blocks_used 3
Key_read_requests 6
Key_reads 3
Key_write_requests 0
Key_writes 0
Locked_connects 0
Max_execution_time_exceeded 0
Max_execution_time_set 0
Max_execution_time_set_failed 0
Max_used_connections 14
Max_used_connections_time 10/01/20 15:50
Not_flushed_delayed_rows 0
Ongoing_anonymous_transaction_count 0
Open_files 0
Open_streams 0
Open_table_definitions 3464
Open_tables 5200
Opened_files 337104
Opened_table_definitions 140571
Opened_tables 76095
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_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
Qcache_free_blocks 1
Qcache_free_memory 16760152
Qcache_hits 0
Qcache_inserts 0
Qcache_lowmem_prunes 0
Qcache_not_cached 184049
Qcache_queries_in_cache 0
Qcache_total_blocks 1
Queries 687716
Questions 684326
Rsa_public_key <removed>
Select_full_join 2827
Select_full_range_join 319
Select_range 56255
Select_range_check 1525
Select_scan 156904
Slave_open_temp_tables 0
Slow_launch_threads 0
Slow_queries 0
Sort_merge_passes 0
Sort_range 61935
Sort_rows 116417
Sort_scan 99600
Table_locks_immediate 458
Table_locks_waited 0
Table_open_cache_hits 381570
Table_open_cache_misses 76095
Table_open_cache_overflows 70888
Tc_log_max_pages_used 0
Tc_log_page_size 0
Tc_log_page_waits 0
Threads_cached 7
Threads_connected 3
Threads_created 14
Threads_running 1
Uptime 424288
Uptime_since_flush_status 424288
Short answer: If you are not swapping and not crashing, there is nothing to worry about. But, since OOM is killing it, then something needs to be tuned lower.
Long answer...
Change swappiness to 1. (It may be defaulted to 60.)
For only 4GB of RAM, do not set innodb_buffer_pool_size to 75-80% of RAM as someone else suggested. You will run out of RAM. Swapping is terrible for performance. Leave it at 1G for now. And this assumes you do not have any other applications running on the machine.
The buffer_pool grows but does not shrink. It is reused. It is a "cache" for blocks of data and indexes of the various tables you are working on.
It sounds like 400MB is chewed up by performance_schema. If you are not using that, turn it off. If you are using it, then lower the buffer_pool to 1000M to make room for PS.
table_open_cache = 5200 -- Do you have thousands of tables? Perhaps 1000 would be safer.
Dozens, even hundreds, of databases is not a problem. table_open_cache is a cache, so it does not need to be as large as the number of tables you have. But, since there are multiple entries for one table when multiple connections are looking at that table, it can be too small.
For further analysis, please provide the info discussed here: http://mysql.rjweb.org/doc.php/mysql_analysis#tuning I will see if there are further clues in the VARIABLES and GLOBAL STATUS.
1K qps is moderately busy (~70th percentile); 10K gets more exciting. Since you seem to have bursts of activity, perhaps you are hitting 10K?
I am not a fan of "throwing hardware at a problem".
An analysis of the settings
Observations:
* Version: 5.7.28-0ubuntu0.16.04.2
* 4 GB of RAM
* Uptime = 4d 21:51:28
* Are you sure this was a SHOW GLOBAL STATUS ?
* You are not running on Windows.
* Running 64-bit version
* You appear to be running entirely (or mostly) InnoDB.
The More Important Issues:
Do not use LOCK TABLES / UNLOCK TABLES with InnoDB. Use transactions. (Or, let's discuss why you are using them.)
innodb_buffer_pool_size = 1G -- or lower if you have a lot of other apps running -- Caution: 1G would make the OOM issue worse, so don't do this until figuring out the OOM problem.
Your system seems to be rather lightly loaded -- except for the number of tables that are open. Can you elaborate on what the app does?
Possibly a lot of inefficient queries. Set long_query_time = 1 and turn on the slowlog.
Details and other observations:
( (key_buffer_size / 0.20 + innodb_buffer_pool_size / 0.70) ) = ((16M / 0.20 + 128M / 0.70)) / 4096M = 6.4% -- Most of available ram should be made available for caching.
-- http://mysql.rjweb.org/doc.php/memory
( table_open_cache ) = 5,200 -- Number of table descriptors to cache
-- Several hundred is usually good.
( Table_open_cache_misses / (Table_open_cache_hits + Table_open_cache_misses) ) = 76,095 / (381570 + 76095) = 16.6% -- Effectiveness of table_open_cache.
-- Increase table_open_cache (now 5200) and check table_open_cache_instances (now 16).
( innodb_buffer_pool_size ) = 128M -- InnoDB Data + Index cache
-- 128M (an old default) is woefully small.
( Innodb_buffer_pool_read_ahead_evicted / Innodb_buffer_pool_read_ahead ) = 552 / 2174 = 25.4% -- Utility of read_ahead.
-- Turn off innodb_random_read_ahead (now OFF).
( Innodb_dblwr_pages_written/Innodb_pages_written ) = 5,776/10525 = 54.9% -- Seems like these values should be equal?
( Innodb_os_log_written / (Uptime / 3600) / innodb_log_files_in_group / innodb_log_file_size ) = 34,017,280 / (424288 / 3600) / 2 / 48M = 0.00287 -- Ratio
-- (see minutes)
( Uptime / 60 * innodb_log_file_size / Innodb_os_log_written ) = 424,288 / 60 * 48M / 34017280 = 10,462 -- Minutes between InnoDB log rotations Beginning with 5.6.8, this can be changed dynamically; be sure to also change my.cnf.
-- (The recommendation of 60 minutes between rotations is somewhat arbitrary.) Adjust innodb_log_file_size (now 50331648). (Cannot change in AWS.)
( innodb_flush_method ) = innodb_flush_method = -- How InnoDB should ask the OS to write blocks. Suggest O_DIRECT or O_ALL_DIRECT (Percona) to avoid double buffering. (At least for Unix.) See chrischandler for caveat about O_ALL_DIRECT
( innodb_flush_neighbors ) = 1 -- A minor optimization when writing blocks to disk.
-- Use 0 for SSD drives; 1 for HDD.
( innodb_io_capacity ) = 200 -- I/O ops per second capable on disk . 100 for slow drives; 200 for spinning drives; 1000-2000 for SSDs; multiply by RAID factor.
( innodb_print_all_deadlocks ) = innodb_print_all_deadlocks = OFF -- Whether to log all Deadlocks.
-- If you are plagued with Deadlocks, turn this on. Caution: If you have lots of deadlocks, this may write a lot to disk.
( character_set_server ) = character_set_server = utf8
-- Charset problems may be helped by setting character_set_server (now utf8) to utf8mb4. That is the future default.
( net_buffer_length / max_allowed_packet ) = 16,384 / 16M = 0.10%
( local_infile ) = local_infile = ON
-- local_infile (now ON) = ON is a potential security issue
( Select_scan / Com_select ) = 156,904 / 290121 = 54.1% -- % of selects doing full table scan. (May be fooled by Stored Routines.)
-- Add indexes / optimize queries
( innodb_autoinc_lock_mode ) = 1 -- Galera: desires 2 -- 2 = "interleaved"; 1 = "consecutive" is typical; 0 = "traditional".
-- Galera desires 2; 2 requires BINLOG_FORMAT=ROW or MIXED
( slow_query_log ) = slow_query_log = OFF -- Whether to log slow queries. (5.1.12)
( long_query_time ) = 10 -- Cutoff (Seconds) for defining a "slow" query.
-- Suggest 2
( log_slow_slave_statements ) = log_slow_slave_statements = OFF -- (5.6.11, 5.7.1) By default, replicated statements won't show up in the slowlog; this causes them to show.
-- It can be helpful in the slowlog to see writes that could be interfering with Slave reads.
( back_log ) = 80 -- (Autosized as of 5.6.6; based on max_connections)
-- Raising to min(150, max_connections (now 151)) may help when doing lots of connections.
You have the Query Cache half-off. You should set both query_cache_type = OFF and query_cache_size = 0 . There is (according to a rumor) a 'bug' in the QC code that leaves some code on unless you turn off both of those settings.
Abnormally small:
Com_insert = 4.6 /HR
Created_tmp_files = 0.051 /HR
Handler_write = 0.33 /sec
Innodb_buffer_pool_bytes_data = 299 /sec
Key_read_requests = 0.051 /HR
Key_reads+Key_writes + Innodb_pages_read+Innodb_pages_written+Innodb_dblwr_writes+Innodb_buffer_pool_pages_flushed = 0.6 /sec
Open_files = 0
Table_locks_immediate = 3.9 /HR
Abnormally large:
Com_unlock_tables = 0.25 /sec
Innodb_num_open_files = 5,200
Open_table_definitions = 3,464
Open_tables = 5,200
performance_schema_max_rwlock_classes = 50
Abnormal strings:
innodb_fast_shutdown = 1
optimizer_trace = enabled=off,one_line=off
optimizer_trace_features = greedy_search=on, range_optimizer=on, dynamic_range=on, repeated_subselect=on
require_secure_transport = ON
slave_rows_search_algorithms = TABLE_SCAN,INDEX_SCAN

Mysql not start on slave system on mysql Ver 14.14 Distrib 5.6.41, version (Mysql master salve replication)?

My Configuration:
server-id = 2
master-host=192.1.1.12
master-connect-retry=60
master-user=root
master-password=root123
replicate-do-db=testdatabase
relay-log = /var/lib/mysql/mysql-relay-bin
relay-log-index = /var/lib/mysql/mysql-relay-bin.index
log-error = /var/lib/mysql/mysql.err
master-info-file = /var/lib/mysql/mysql-master.info
relay-log-info-file = /var/lib/mysql/mysql-relay-log.info
log-bin = /var/lib/mysql/mysql-bin
Output:
2018-09-14 08:41:10 13635 [ERROR] /usr/sbin/mysqld: unknown variable 'master-host=192.1.1.12'
2018-09-14 08:41:10 13635 [ERROR] Aborting
2018-09-14 08:41:10 13635 [Note] Binlog end
2018-09-14 08:41:10 13635 [Note] Shutting down plugin 'partition'
2018-09-14 08:41:10 13635 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
The master-host, -user, and -password option variables were removed from MySQL 5.5. Use the CHANGE MASTER statement instead.
https://dev.mysql.com/doc/refman/5.5/en/replication-options-slave.html#replication-optvars-slaves-obsolete

Percona Xtradb Cluster failing

I have setup Percona Xtradb cluster with 3 nodes. The first node starts fine with bootstrap, but when I try to start the second node to join the cluster, I get the following error:
2015-08-27 18:08:08 25990 [Warning] WSREP: Failed to prepare for incremental state transfer: Local state UUID (00000000-0000-0000-0000-000000000000) does not match group state UUID (a6b3fced-4ca1-11e5-b5da-d69fa186273c): 1 (Operation not permitted)
at galera/src/replicator_str.cpp:prepare_for_IST():463. IST will be unavailable.
2015-08-27 18:08:08 25990 [Note] WSREP: Member 0.0 (db-gc-pxc2) requested state transfer from 'any'. Selected 1.0 (db-gc-pxc1)(SYNCED) as donor.
2015-08-27 18:08:08 25990 [Note] WSREP: Shifting PRIMARY -> JOINER (TO: 0)
2015-08-27 18:08:08 25990 [Note] WSREP: Requesting state transfer: success, donor: 1
2015-08-27 18:08:08 25990 [Warning] WSREP: 1.0 (db-gc-pxc1): State transfer to 0.0 (db-gc-pxc2) failed: -12 (Cannot allocate memory)
2015-08-27 18:08:08 25990 [ERROR] WSREP: gcs/src/gcs_group.cpp:int gcs_group_handle_join_msg(gcs_group_t*, const gcs_recv_msg_t*)():731: Will never receive state. Need to abort.
2015-08-27 18:08:08 25990 [Note] WSREP: gcomm: terminating thread
2015-08-27 18:08:08 25990 [Note] WSREP: gcomm: joining thread
2015-08-27 18:08:08 25990 [Note] WSREP: gcomm: closing backend
Below is my cluster config in my.cnf file:
# Galera COnfig
wsrep_cluster_name = pxc
wsrep_cluster_address = gcomm://192.168.2.100,192.168.2.101,10.168.1.102
wsrep_node_address = 10.1.0.101
wsrep_provider = /usr/lib/libgalera_smm.so
wsrep_provider_options = "gcache.size=4G"
wsrep_slave_threads = 32
wsrep_sst_auth = "user:userpass"
wsrep_node_name = node2
#wsrep_sst_method = xtrabackup_throttle
wsrep_sst_method = xtrabackup-v2
What would be causing this error?
FYI, I do have the user and password for wsrep_sst_auth created in the database.
Here is the remainder of the my.cnf it it helps:
back_log = 65535
binlog_format = ROW
character_set_server = utf8
collation_server = utf8_general_ci
datadir = /var/lib/mysql
#default_storage_engine = InnoDB
expand_fast_index_creation = 1
expire_logs_days = 7
innodb_autoinc_lock_mode = 2
innodb_buffer_pool_instances = 6
innodb_buffer_pool_populate = 1
innodb_buffer_pool_size = 6G # XXX 64GB RAM, 80%
#innodb_data_file_path = ibdata1:64M;ibdata2:64M:autoextend
innodb_file_format = Barracuda
innodb_file_per_table
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_io_capacity = 1600
innodb_large_prefix
innodb_locks_unsafe_for_binlog = 1
#innodb_log_file_size = 64M
innodb_print_all_deadlocks = 1
innodb_read_io_threads = 64
innodb_stats_on_metadata = FALSE
innodb_support_xa = FALSE
innodb_write_io_threads = 64
log-bin = mysqld-bin
log-queries-not-using-indexes
log-slave-updates
long_query_time = 1
max_allowed_packet = 64M
max_connect_errors = 4294967295
max_connections = 4096
min_examined_row_limit = 1000
performance-schema-instrument='%=ON'
port = 3306
relay-log-recovery = TRUE
skip-name-resolve
slow_query_log = 1
slow_query_log_timestamp_always = 1
table_open_cache = 4096
thread_cache = 1024
tmpdir = /srv/tmp
transaction_isolation = REPEATABLE-READ
updatable_views_with_limit = 0
user = mysql
wait_timeout = 60
This would seem to be the root cause:
2015-08-27 18:08:08 25990 [Warning] WSREP: 1.0 (db-gc-pxc1): State transfer to 0.0 (db-gc-pxc2) failed: -12 (Cannot allocate memory)
The new node tries to join the cluster. The new node has no state currently (local UUID is zeroes), and so an IST is not available - this means it needs to run a full SST form the donor node.
Node pxc2 is the joiner and pxc1 is the selected donor; however we get an error from pxc1 that the state transfer failed, which causes the joining to fail.
You should check the logs on the donor node (pxc1) for more detail; but the log we have indicates that it has insufficient memory to run the export of the database. Not knowing your hardware configuration, I can't give a definite response, but most likely your my.cnf is configured to be too memory hungry for your available memory and so the xtrabackup process cannot run, or else the database is too large. Add more memory to the node, or else reduce the allocations in the my.cnf.

MySQL excessive memory usage

I have an installation of MySQL which allocates a lot more memory than I expected. I'd like to understand where it has gone to fix the root cause.
To estimate the RAM usage I use this formula:
key_buffer_size + query_cache_size + innodb_buffer_pool_size + innodb_additional_mem_pool_size + innodb_log_buffer_size + Max_used_connections * (read_buffer_size + read_rnd_buffer_size + sort_buffer_size+ join_buffer_size+ binlog_cache_size + thread_stack + tmp_table_size)
This formula produces around 5.3 GB of estimated allocation.
Instead, the RAM used by MySQL continues to grow and, after a couple of days of activity, it goes well over 9 GB (writing heavily into swap).
What am I forgetting? How can I understand who is eating the remaining RAM?
A few more pieces of information.
I'm running MySQL CE 5.6.17 on RHEL6.3 64 bits. My server has 6 GB RAM and 8GB swap space.
I have constantly around 150 alive connections to MySQL but I'm keeping max_connections to higher values to accommodate peaks and foresee some more traffic on this machine.
I'm only using InnoDB.
My application uses pooled connections to the DB. The producers open connections and release them to the pool when they are done. I have measured that I always have several parallel requests, and pooling speeds up a little bit connections creation (so faster queries). The pool (DBCP) auto-tunes a reasonable number of alive connections and it's usually around 100-150.
I have already tried:
killing the connections does not free RAM
FLUSH TABLES does not free RAM
Following my config:
---- my.cnf -----
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 1M
table_open_cache = 256
key_buffer_size = 128M
sort_buffer_size = 524288
read_buffer_size = 131072
read_rnd_buffer_size = 524288
myisam_sort_buffer_size = 524288
tmp_table_size=10M
performance_schema=0
thread_cache_size = 50
query_cache_type = OFF
query_cache_size = 0
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
innodb_data_home_dir = "/data/mysqldata"
innodb_log_group_home_dir = "/data1/mysqllog"
innodb_buffer_pool_size = 3000M
innodb_buffer_pool_instances = 3
innodb_log_file_size = 750M
innodb_flush_log_at_trx_commit = 2
datadir = "/data/mysqldata"
innodb_flush_method=O_DIRECT
max_connections = 1650
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 10
autocommit=1
init-connect='SET NAMES utf8'
character-set-server = utf8
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
default-character-set=utf8
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
---------
This is the memory allocated to mysql after few days of activity:
[root#G-VelocityDB ~]# ps aux | grep mysql
root 1963 0.0 0.0 108332 1492 ? S May09 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/data/mysqldata --pid-file=/data/mysqldata/G-VelocityDB.pid
mysql 2583 80.4 88.3 9816560 8949704 ? Sl May09 3538:34 /usr/sbin/mysqld --basedir=/usr --datadir=/data/mysqldata --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/data/mysqldata/G-VelocityDB.err --pid-file=/data/mysqldata/G-VelocityDB.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 21450 0.0 0.0 103244 852 pts/1 S+ 08:51 0:00 grep mysql
# cat /proc/2583/status
Name: mysqld
State: S (sleeping)
Tgid: 2583
Pid: 2583
PPid: 1963
TracerPid: 0
Uid: 496 496 496 496
Gid: 493 493 493 493
Utrace: 0
FDSize: 512
Groups: 493
VmPeak: 9882096 kB
VmSize: 9816560 kB
VmLck: 0 kB
VmHWM: 8950684 kB
VmRSS: 8949652 kB
VmData: 9771648 kB
VmStk: 88 kB
VmExe: 11684 kB
VmLib: 3928 kB
VmPTE: 17996 kB
VmSwap: 0 kB
Threads: 161
SigQ: 0/78996
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000087007
SigIgn: 0000000000001006
SigCgt: 00000001800066e9
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: ffffffffffffffff
Cpus_allowed: 3
Cpus_allowed_list: 0-1
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 15496
nonvoluntary_ctxt_switches: 337
Some more info on my server:
GLOBAL STATUS:
Aborted_clients............ 237
Aborted_connects............. 10
Binlog_cache_disk_use.......... 0
Binlog_cache_use............. 0
Binlog_stmt_cache_disk_use......... 0
Binlog_stmt_cache_use.......... 0
Bytes_received............. 4194923507
Bytes_sent............. 11895871264
Com_admin_commands........... 455
Com_assign_to_keycache........... 0
Com_alter_db............. 0
Com_alter_db_upgrade........... 0
Com_alter_event............ 0
Com_alter_function........... 0
Com_alter_procedure.......... 0
Com_alter_server............. 0
Com_alter_table............ 0
Com_alter_tablespace........... 0
Com_alter_user............. 0
Com_analyze............ 0
Com_begin.............. 2
Com_binlog............. 0
Com_call_procedure........... 4868660
Com_change_db............ 8
Com_change_master............ 0
Com_check.............. 0
Com_checksum............. 0
Com_create_db............ 0
Com_create_event............. 0
Com_create_function.......... 0
Com_create_index............. 0
Com_create_procedure........... 0
Com_create_server............ 0
Com_create_table............. 0
Com_create_trigger........... 0
Com_create_udf............. 0
Com_create_user............ 0
Com_create_view............ 0
Com_dealloc_sql............ 0
Com_delete............. 19742
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_server............ 0
Com_drop_table............. 0
Com_drop_trigger............. 0
Com_drop_user............ 0
Com_drop_view............ 0
Com_empty_query............ 0
Com_execute_sql............ 0
Com_flush.............. 0
Com_get_diagnostics.......... 0
Com_grant.............. 0
Com_ha_close............. 0
Com_ha_open............ 0
Com_ha_read............ 0
Com_help............... 57
Com_insert............. 7149329
Com_insert_select............ 44
Com_install_plugin........... 0
Com_kill............... 0
Com_load............... 0
Com_lock_tables............ 0
Com_optimize............. 0
Com_preload_keys............. 0
Com_prepare_sql............ 0
Com_purge.............. 0
Com_purge_before_date.......... 0
Com_release_savepoint.......... 0
Com_rename_table............. 0
Com_rename_user............ 0
Com_repair............. 0
Com_replace............ 0
Com_replace_select........... 0
Com_reset.............. 0
Com_resignal............. 0
Com_revoke............. 0
Com_revoke_all............. 0
Com_rollback............. 6366209
Com_rollback_to_savepoint.......... 0
Com_savepoint............ 0
Com_select............. 16223159
Com_set_option............. 13471816
Com_signal............. 0
Com_show_binlog_events........... 0
Com_show_binlogs............. 0
Com_show_charsets............ 0
Com_show_collations.......... 632
Com_show_create_db........... 0
Com_show_create_event.......... 0
Com_show_create_func........... 0
Com_show_create_proc........... 0
Com_show_create_table.......... 0
Com_show_create_trigger.......... 0
Com_show_databases........... 21
Com_show_engine_logs........... 0
Com_show_engine_mutex.......... 0
Com_show_engine_status........... 0
Com_show_events............ 0
Com_show_errors............ 0
Com_show_fields............ 101
Com_show_function_code........... 0
Com_show_function_status........... 3
Com_show_grants............ 0
Com_show_keys............ 9
Com_show_master_status........... 0
Com_show_open_tables........... 0
Com_show_plugins............. 2
Com_show_privileges.......... 0
Com_show_procedure_code.......... 0
Com_show_procedure_status.......... 3
Com_show_processlist........... 0
Com_show_profile............. 0
Com_show_profiles............ 0
Com_show_relaylog_events........... 0
Com_show_slave_hosts........... 0
Com_show_slave_status.......... 2
Com_show_status............ 805
Com_show_storage_engines........... 0
Com_show_table_status.......... 0
Com_show_tables............ 13
Com_show_triggers............ 0
Com_show_variables........... 667
Com_show_warnings............ 0
Com_slave_start............ 0
Com_slave_stop............. 0
Com_stmt_close............. 0
Com_stmt_execute............. 0
Com_stmt_fetch............. 0
Com_stmt_prepare............. 0
Com_stmt_reprepare........... 0
Com_stmt_reset............. 0
Com_stmt_send_long_data.......... 0
Com_truncate............. 0
Com_uninstall_plugin........... 0
Com_unlock_tables............ 0
Com_update............. 168248
Com_update_multi............. 0
Com_xa_commit............ 0
Com_xa_end............. 0
Com_xa_prepare............. 0
Com_xa_recover............. 0
Com_xa_rollback............ 0
Com_xa_start............. 0
Compression............ OFF
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............ 670
Created_tmp_disk_tables.......... 838
Created_tmp_files............ 6
Created_tmp_tables........... 5214
Delayed_errors............. 0
Delayed_insert_threads........... 0
Delayed_writes............. 0
Flush_commands............. 1
Handler_commit............. 30081211
Handler_delete............. 6300384
Handler_discover............. 0
Handler_external_lock.......... 67018766
Handler_mrr_init............. 0
Handler_prepare............ 0
Handler_read_first........... 11247573
Handler_read_key............. 22140615
Handler_read_last............ 0
Handler_read_next............ 1099116268
Handler_read_prev............ 26294847
Handler_read_rnd............. 38722
Handler_read_rnd_next.......... 22705321
Handler_rollback............. 60
Handler_savepoint............ 0
Handler_savepoint_rollback......... 0
Handler_update............. 167974
Handler_write............ 7852897
Innodb_buffer_pool_dump_status......... not started
Innodb_buffer_pool_load_status......... not started
Innodb_buffer_pool_pages_data........ 186890
Innodb_buffer_pool_bytes_data........ 3062005760
Innodb_buffer_pool_pages_dirty......... 6539
Innodb_buffer_pool_bytes_dirty......... 107134976
Innodb_buffer_pool_pages_flushed......... 584944
Innodb_buffer_pool_pages_free........ 3072
Innodb_buffer_pool_pages_misc........ 2035
Innodb_buffer_pool_pages_total......... 191997
Innodb_buffer_pool_read_ahead_rnd........ 0
Innodb_buffer_pool_read_ahead........ 129315
Innodb_buffer_pool_read_ahead_evicted...... 0
Innodb_buffer_pool_read_requests......... 531706692
Innodb_buffer_pool_reads........... 215710
Innodb_buffer_pool_wait_free......... 0
Innodb_buffer_pool_write_requests........ 84850509
Innodb_data_fsyncs........... 445789
Innodb_data_pending_fsyncs......... 0
Innodb_data_pending_reads.......... 0
Innodb_data_pending_writes......... 0
Innodb_data_read............. 5930536960
Innodb_data_reads............ 379282
Innodb_data_writes........... 3707043
Innodb_data_written.......... 24355757056
Innodb_dblwr_pages_written......... 584944
Innodb_dblwr_writes.......... 16463
Innodb_have_atomic_builtins........ ON
Innodb_log_waits............. 0
Innodb_log_write_requests.......... 8093999
Innodb_log_writes............ 3091626
Innodb_os_log_fsyncs........... 168887
Innodb_os_log_pending_fsyncs......... 0
Innodb_os_log_pending_writes......... 0
Innodb_os_log_written.......... 5187414528
Innodb_page_size............. 16384
Innodb_pages_created........... 76352
Innodb_pages_read............ 358104
Innodb_pages_written........... 584944
Innodb_row_lock_current_waits........ 0
Innodb_row_lock_time........... 17326
Innodb_row_lock_time_avg........... 18
Innodb_row_lock_time_max........... 1027
Innodb_row_lock_waits.......... 946
Innodb_rows_deleted.......... 6300384
Innodb_rows_inserted........... 7149273
Innodb_rows_read............. 1140478060
Innodb_rows_updated.......... 164739
Innodb_num_open_files.......... 300
Innodb_truncated_status_writes......... 0
Innodb_available_undo_logs......... 128
Key_blocks_not_flushed........... 0
Key_blocks_unused............ 107146
Key_blocks_used............ 25
Key_read_requests............ 811
Key_reads.............. 25
Key_write_requests........... 0
Key_writes............. 0
Last_query_cost............ 0.000000
Last_query_partial_plans........... 0
Max_used_connections........... 172
Not_flushed_delayed_rows........... 0
Open_files............. 11
Open_streams............. 0
Open_table_definitions........... 69
Open_tables............ 256
Opened_files............. 3701
Opened_table_definitions........... 69
Opened_tables............ 308
Prepared_stmt_count.......... 0
Queries.............. 54874967
Questions.............. 49932690
Select_full_join............. 1196
Select_full_range_join........... 0
Select_range............. 494248
Select_range_check........... 0
Select_scan............ 9551157
Slow_launch_threads.......... 0
Slow_queries............. 63
Sort_merge_passes............ 0
Sort_range............. 1
Sort_rows.............. 45942
Sort_scan.............. 2550
Table_locks_immediate.......... 26010899
Table_locks_waited........... 0
Table_open_cache_hits.......... 24039437
Table_open_cache_misses.......... 308
Table_open_cache_overflows......... 45
Tc_log_max_pages_used.......... 0
Tc_log_page_size............. 0
Tc_log_page_waits............ 0
Threads_cached............. 47
Threads_connected............ 102
Threads_created............ 282
Threads_running............ 1
Uptime............... 171023
Uptime_since_flush_status.......... 171023
Com_commit............. 6536509
SHOW ENGINE INNODB STATUS;
Per second averages calculated from the last 17 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 268650 srv_active, 0 srv_shutdown, 12135 srv_idle
srv_master_thread log flush and writes: 280785
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 1688081
OS WAIT ARRAY INFO: signal count 957822
Mutex spin waits 1873319, rounds 44188913, OS waits 1295453
RW-shared spins 469687, rounds 12569665, OS waits 334361
RW-excl spins 35863, rounds 1100713, OS waits 24644
Spin rounds per wait: 23.59 mutex, 26.76 RW-shared, 30.69 RW-excl
------------------------
LATEST DETECTED DEADLOCK
------------------------
2014-05-07 17:22:56 7f0d94a1a700
*** (1) TRANSACTION:
TRANSACTION 1119978000, ACTIVE 0 sec starting index read
mysql tables in use 10, locked 10
LOCK WAIT 7 lock struct(s), heap size 1184, 2 row lock(s)
MySQL thread id 69, OS thread handle 0x7f0d91c0d700, query id 73382628 g-velocity.abodata.domain 10.0.2.180 platone updating
DELETE FROM PacketDay PARTITION(p1730,p1731,p1732,p1733,p1734,p1735,p1736,p1737,p1738,p1739) WHERE XXXX=4 AND StartTime<1399388476900 LIMIT 50000
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 5831 page no 27 n bits 224 index `PRIMARY` of table `ViewDb`.`PacketDay` /* Partition `p1732` */ trx id 1119978000 lock_mode X locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 17; compact format; info bits 32
0: len 8; hex 80000145cf7ab51d; asc E z ;;
1: len 4; hex 80000e94; asc ;;
2: len 6; hex 000042c1820e; asc B ;;
3: len 7; hex 65000480151812; asc e ;;
4: len 4; hex 80000005; asc ;;
5: len 8; hex 80000145cf7ab51d; asc E z ;;
6: len 8; hex 8000000000000000; asc ;;
7: len 4; hex 80000004; asc ;;
8: len 4; hex 80000003; asc ;;
9: SQL NULL;
10: len 8; hex 0000000000001c40; asc #;;
11: len 0; hex ; asc ;;
12: len 1; hex 30; asc 0;;
13: len 2; hex 8001; asc ;;
14: len 4; hex 80000000; asc ;;
15: len 8; hex 80000145cf7ab3b6; asc E z ;;
16: len 24; hex 5b303d4f66662c20313d52696768742c20323d4c6566745d; asc [0=Off, 1=Right, 2=Left];;
*** (2) TRANSACTION:
TRANSACTION 1119977998, ACTIVE 0 sec updating or deleting
mysql tables in use 10, locked 10
32 lock struct(s), heap size 6544, 6 row lock(s), undo log entries 1
MySQL thread id 36, OS thread handle 0x7f0d94a1a700, query id 73382652 g-velocity.abodata.domain 10.0.2.180 platone updating
DELETE FROM PacketDay PARTITION(p1730,p1731,p1732,p1733,p1734,p1735,p1736,p1737,p1738,p1739) WHERE XXXX=5 AND StartTime<1399388476871 LIMIT 50000
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 5831 page no 27 n bits 224 index `PRIMARY` of table `ViewDb`.`PacketDay` /* Partition `p1732` */ trx id 1119977998 lock_mode X locks rec but not gap
Record lock, heap no 2 PHYSICAL RECORD: n_fields 17; compact format; info bits 32
0: len 8; hex 80000145cf7ab51d; asc E z ;;
1: len 4; hex 80000e94; asc ;;
2: len 6; hex 000042c1820e; asc B ;;
3: len 7; hex 65000480151812; asc e ;;
4: len 4; hex 80000005; asc ;;
5: len 8; hex 80000145cf7ab51d; asc E z ;;
6: len 8; hex 8000000000000000; asc ;;
7: len 4; hex 80000004; asc ;;
8: len 4; hex 80000003; asc ;;
9: SQL NULL;
10: len 8; hex 0000000000001c40; asc #;;
11: len 0; hex ; asc ;;
12: len 1; hex 30; asc 0;;
13: len 2; hex 8001; asc ;;
14: len 4; hex 80000000; asc ;;
15: len 8; hex 80000145cf7ab3b6; asc E z ;;
16: len 24; hex 5b303d4f66662c20313d52696768742c20323d4c6566745d; asc [0=Off, 1=Right, 2=Left];;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 5831 page no 28 n bits 824 index `idx_XXXX_YYYY` of table `AAAA`.`PacketDay` /* Partition `p1732` */ trx id 1119977998 lock_mode X locks rec but not gap waiting
Record lock, heap no 686 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
0: len 4; hex 80000005; asc ;;
1: len 8; hex 80000145cf7ab51d; asc E z ;;
2: len 4; hex 80000e94; asc ;;
*** WE ROLL BACK TRANSACTION (1)
------------
TRANSACTIONS
------------
Trx id counter 1136364858
Purge done for trx's n:o < 1136364106 undo n:o < 0 state: running but idle
History list length 984
LIST OF TRANSACTIONS FOR EACH SESSION:
[...]
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
1320822 OS file reads, 8503653 OS file writes, 2583777 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.12 writes/s, 0.06 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 67353, seg size 67355, 5035 merges
merged operations:
insert 65890, delete mark 110773, delete 319
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 6225523, node heap has 1792 buffer(s)
0.06 hash searches/s, 0.94 non-hash searches/s
---
LOG
---
Log sequence number 291212776237
Log flushed up to 291212776237
Pages flushed up to 291114806316
Last checkpoint at 291114806316
0 pending log writes, 0 pending chkp writes
4968792 log i/o's done, 0.12 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 3219456000; in additional pool allocated 0
Dictionary memory allocated 36167844
Buffer pool size 191997
Free buffers 3072
Database pages 187133
Old database pages 69022
Modified db pages 8213
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 653753, not young 38903623
0.00 youngs/s, 0.00 non-youngs/s
Pages read 1310744, created 130762, written 3414584
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 187133, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size 63999
Free buffers 1024
Database pages 62402
Old database pages 23015
Modified db pages 2482
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 197235, not young 11921942
0.00 youngs/s, 0.00 non-youngs/s
Pages read 423522, created 40807, written 1078968
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 62402, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size 63999
Free buffers 1024
Database pages 62366
Old database pages 23006
Modified db pages 2909
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 219800, not young 13508215
0.00 youngs/s, 0.00 non-youngs/s
Pages read 439314, created 44996, written 1162507
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 62366, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 2
Buffer pool size 63999
Free buffers 1024
Database pages 62365
Old database pages 23001
Modified db pages 2822
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 236718, not young 13473466
0.00 youngs/s, 0.00 non-youngs/s
Pages read 447908, created 44959, written 1173109
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 62365, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
7 read views open inside InnoDB
Main thread process no. 5965, id 139696323659520, state: sleeping
Number of rows inserted 13664081, updated 230718, deleted 8001095, read 31517028476
0.06 inserts/s, 0.06 updates/s, 0.00 deletes/s, 43.59 reads/s
select sum(data_length+index_length) from information_schema.tables where engine='memory';
Result: '0'
As suggested, I have run with and without partitioning enabled on my server (I have 5 tables with 2000 partitions each), and seems that disabling partitioning helps in some way. But still I have not clear the reason, and I cannot eliminate partitioning at all.
As suggested, I have run some basic test running mysql under valgrind for leak detection: http://pastebin.com/W3ZMAGY4
And massif: http://pastebin.com/LweQHn3M
These tests are executed with MySQL default configuration.
If I'm reading the output correctly, no relevant leak is found and I have a huge memory consumption per connection (500 MB each connection).
Is that correct? Any idea why it grows so much?
The InnoDB data dictionary can grow without bounds as you open many tables, beyond innodb_additional_mem_pool_size, and it often does grow huge if you have thousands of tables. This would be independent of the number of connections.
I've seen other people report that MySQL 5.6 has a lot of memory usage, but we haven't tracked it down definitively. One would have to run mysqld under valgrind to track memory growth.
MySQL 5.7 is still under development, but they are creating new PERFORMANCE_SCHEMA instruments to track memory usage.
If the memory reported by the InnoDB data dictionary alone doesn't account for the memory growth, I suggest reading the following bug reports to see if they apply in your case:
Bug #72322 Query to I_S.tables and I_S.columns leads to huge memory usage
Bug #68514 5.6 huge memory usage with max_connections parameter
Bug #57480 Memory leak when having 256+ tables