1. 程式人生 > >MYSQL5.6重要引數

MYSQL5.6重要引數

版本msyql5.6,原筆記上面的有些粗糙

一、線上mysql修改timeout值

show processlist;

 set global interactive_timeout=400;

set global wait_timeout=400;

Exit

二、關於線上innodb引數使用情況

mysql> show global status like 'innodb_buffer_pool_pages%';

+----------------------------------+---------+

| Variable_name                    | Value   |

+----------------------------------+---------+

| Innodb_buffer_pool_pages_data    | 384598  |   //使用頁

| Innodb_buffer_pool_pages_dirty   | 476     |

| Innodb_buffer_pool_pages_flushed | 1329814 |

| Innodb_buffer_pool_pages_free    | 3072    |  //空閒頁

| Innodb_buffer_pool_pages_misc    | 5544    |

| Innodb_buffer_pool_pages_total   | 393214  |   //總頁數

+----------------------------------+---------+

空閒頁面很多,說明設定過大,相反如果空閒頁面少,說明需要調大;

——————————————————————————————————

mysql> show variables like 'innodb_log%';

+-----------------------------+-----------+

| Variable_name               | Value     |

+-----------------------------+-----------+

| innodb_log_buffer_size      | 8388608   | //把這次改動的記錄寫到日誌快取中

mysql> show global status like '%innodb_log_waits%';

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| Innodb_log_waits | 0     |  //大於0,繼續增大,要調整innodb_log_buffer_size大小,取值16MB-64MB

+------------------+-------+

show global status like '%binlog_cache%';

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    17122163

Current database: *** NONE ***

+-----------------------+--------+

| Variable_name         | Value  |

+-----------------------+--------+

| Binlog_cache_disk_use | 3306   |  //不為0.說明磁碟上的臨時檔案被用上, 要調binlog_cache_size

| Binlog_cache_use      | 593010 |

+-----------------------+--------+

mysqldumpslow  -s t -t 10 /data/mysql/mysql-slow.log

查詢的結果是10條執行時間最慢的sql語句,其中-s t是指此類型別的語句的執

Time=3.73s (2205s) 最長的執行時間,2205統計用的時間

關於慢查詢 slow

Mysqldumpslow 不好用情況下,percona-toolkit工具,pt-query-digest

mysqldumpslow -s t -t 10 /data/mysql/mysql-slow.log

Pt-query-digest --since=24h /data/mysql/slow.log >query.log

分析24小時query.log   overall 總有多少條查詢

       Time range:查詢執行的時間範圍

Unique:唯一查詢數量

   Total:

   95%:小到大排列

 Median:中位數

Pid檔案,將自己唯一程序號記錄到自己pid檔案中

Socket檔案:是伺服器與本地客戶端進行通訊的UNIX套接字檔案

對記錄做變更操作時不僅會產生redo記錄,也會產生undo記錄(insert update delete),但undo只記錄變更前的舊資料

Show global status

+-----------------------------------------------+---------------------+

| Variable_name                                 | Value               |

+-----------------------------------------------+---------------------+

| Aborted_clients                               | 70979               |//客戶端沒有正確關閉連線導致客戶端連線終止,以及連線超時

| Aborted_connects                              | 466                 |//連線資料庫失敗的連線數

| Binlog_cache_disk_use                         | 3308                |//臨時二進位制日誌快取,是超過binlog_cache_size值並使用臨時檔案來儲存事務中語句的事務數量

| Binlog_cache_use                              | 599563              | //使用臨時二進位制日誌快取事物數量

| Binlog_stmt_cache_disk_use                    | 2741                |//當非事物語句使用二進位制日誌快取,但是超出binlog_stmt_cache_size大小時,就會使用一個臨時檔案來存放這些語句

| Binlog_stmt_cache_use                         | 4027                | //使用二進位制日誌快取檔案的非事物語句數量

| Bytes_received                                | 12624572922         |

| Bytes_sent                                    | 38490032931         |

| Com_admin_commands                            | 1220886             |

| 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                               | 486                 |

| Com_alter_tablespace                          | 0                   |

| Com_alter_user                                | 0                   |

| Com_analyze                                   | 0                   |

| Com_begin                                     | 10954               |

| Com_binlog                                    | 0                   |

| Com_call_procedure                            | 0                   |

| Com_change_db                                 | 41989               |

| Com_change_master                             | 3                   |

| Com_check                                     | 0                   |

| Com_checksum                                  | 0                   |

| Com_commit                                    | 457143              |

| Com_create_db                                 | 8                   |

| Com_create_event                              | 0                   |

| Com_create_function                           | 0                   |

| Com_create_index                              | 0                   |

| Com_create_procedure                          | 0                   |

| Com_create_server                             | 0                   |

| Com_create_table                              | 233                 |

| Com_create_trigger                            | 3                   |

| Com_create_udf                                | 0                   |

| Com_create_user                               | 0                   |

| Com_create_view                               | 0                   |

| Com_dealloc_sql                               | 0                   |

| Com_delete                                    | 388                 |

| Com_delete_multi                              | 0                   |

| Com_do                                        | 0                   |

| Com_drop_db                                   | 4                   |

| Com_drop_event                                | 0                   |

| Com_drop_function                             | 0                   |

| Com_drop_index                                | 0                   |

| Com_drop_procedure                            | 0                   |

| Com_drop_server                               | 0                   |

| Com_drop_table                                | 235                 |

| Com_drop_trigger                              | 0                   |

| Com_drop_user                                 | 0                   |

| Com_drop_view                                 | 0                   |

| Com_empty_query                               | 0                   |

| Com_execute_sql                               | 0                   |

| Com_flush                                     | 5                   |

| Com_get_diagnostics                           | 0                   |

| Com_grant                                     | 2                   |

| Com_ha_close                                  | 0                   |

| Com_ha_open                                   | 0                   |

| Com_ha_read                                   | 0                   |

| Com_help                                      | 0                   |

| Com_insert                                    | 549789              |

| Com_insert_select                             | 0                   |

| Com_install_plugin                            | 0                   |

| Com_kill                                      | 0                   |

| Com_load                                      | 0                   |

| Com_lock_tables                               | 231                 |

| 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                                   | 59                  |

| Com_replace_select                            | 0                   |

| Com_reset                                     | 4                   |

| Com_resignal                                  | 0                   |

| Com_revoke                                    | 0                   |

| Com_revoke_all                                | 0                   |

| Com_rollback                                  | 404                 |

| Com_rollback_to_savepoint                     | 0                   |

| Com_savepoint                                 | 0                   |

| Com_select                                    | 30597749            |

| Com_set_option                                | 18025324            |

| Com_signal                                    | 0                   |

| Com_show_binlog_events                        | 0                   |

| Com_show_binlogs                              | 0                   |

| Com_show_charsets                             | 11                  |

| Com_show_collations                           | 11                  |

| Com_show_create_db                            | 10                  |

| Com_show_create_event                         | 0                   |

| Com_show_create_func                          | 0                   |

| Com_show_create_proc                          | 0                   |

| Com_show_create_table                         | 3132                |

| Com_show_create_trigger                       | 3                   |

| Com_show_databases                            | 72                  |

| 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                               | 10240               |

| Com_show_function_code                        | 0                   |

| Com_show_function_status                      | 8                   |

| Com_show_grants                               | 0                   |

| Com_show_keys                                 | 199                 |

| Com_show_master_status                        | 156                 |

| Com_show_open_tables                          | 0                   |

| Com_show_plugins                              | 0                   |

| Com_show_privileges                           | 0                   |

| Com_show_procedure_code                       | 0                   |

| Com_show_procedure_status                     | 8                   |

| Com_show_processlist                          | 52                  |

| Com_show_profile                              | 0                   |

| Com_show_profiles                             | 0                   |

| Com_show_relaylog_events                      | 0                   |

| Com_show_slave_hosts                          | 0                   |

| Com_show_slave_status                         | 123                 |

| Com_show_status                               | 86                  |

| Com_show_storage_engines                      | 29                  |

| Com_show_table_status                         | 1160                |

| Com_show_tables                               | 158                 |

| Com_show_triggers                             | 920                 |

| Com_show_variables                            | 146                 |

| Com_show_warnings                             | 0                   |

| Com_slave_start                               | 4                   |

| Com_slave_stop                                | 5                   |

| Com_stmt_close                                | 25984               |

| Com_stmt_execute                              | 25984               |

| Com_stmt_fetch                                | 0                   |

| Com_stmt_prepare                              | 25984               |

| Com_stmt_reprepare                            | 0                   |

| Com_stmt_reset                                | 0                   |

| Com_stmt_send_long_data                       | 0                   |

| Com_truncate                                  | 0                   |

| Com_uninstall_plugin                          | 0                   |

| Com_unlock_tables                             | 231                 |

| Com_update                                    | 549840              |

| 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                                   | 17286940            |

| Created_tmp_disk_tables                       | 21299               | //伺服器執行語句時在硬碟上自動建立的臨時表的數量

| Created_tmp_files                             | 4983                | //伺服器執行語句時自動建立的記憶體中的臨時表的數量,如果Created_tmp_disk_tables引數大,可能要增加tmp_table_size值,使臨時表基於記憶體而不基於硬碟

Created_tmp_disk_tables / Created_tmp_tables * 100% <= 25% 比較好

| Created_tmp_tables                            | 146943              |

| Delayed_errors                                | 0                   |

| Delayed_insert_threads                        | 0                   |

| Delayed_writes                                | 0                   |

| Flush_commands                                | 3                   |

| Handler_commit                                | 33633280            |//內部提交語句數量

| Handler_delete                                | 450901              |

| Handler_discover                              | 0                   |

| Handler_external_lock                         | 72477269            |

| Handler_mrr_init                              | 0                   |

| Handler_prepare                               | 3052914             |

| Handler_read_first                            | 1218011             |

| Handler_read_key                              | 122750038676        |

| Handler_read_last                             | 304457              |

| Handler_read_next                             | 1836980702077       |

| Handler_read_prev                             | 54873155031         |

| Handler_read_rnd                              | 119396899834        |

| Handler_read_rnd_next                         | 55736189757         |

| Handler_rollback                              | 174                 |

| Handler_savepoint                             | 0                   |

| Handler_savepoint_rollback                    | 0                   |

| Handler_update                                | 868882084           |

| Handler_write                                 | 810135258           |

| Innodb_buffer_pool_dump_status                | not started         |

| Innodb_buffer_pool_load_status                | not started         |

| Innodb_buffer_pool_pages_data                 | 384599              |

| Innodb_buffer_pool_bytes_data                 | 6301270016          |

| Innodb_buffer_pool_pages_dirty                | 1010                |

| Innodb_buffer_pool_bytes_dirty                | 16547840            |

| Innodb_buffer_pool_pages_flushed              | 1348133             |

| Innodb_buffer_pool_pages_free                 | 3085                |

| Innodb_buffer_pool_pages_misc                 | 5530                |

| Innodb_buffer_pool_pages_total                | 393214              |

| Innodb_buffer_pool_read_ahead_rnd             | 0                   |

| Innodb_buffer_pool_read_ahead                 | 59653               |

| Innodb_buffer_pool_read_ahead_evicted         | 0                   |

| Innodb_buffer_pool_read_requests              | 522476284584        |

| Innodb_buffer_pool_reads                      | 27587               |

| Innodb_buffer_pool_wait_free                  | 0                   |//通過後臺向innodb快取池頁,

如果該值大於0,需要增加innodb_buffer_pool大小

| Innodb_buffer_pool_write_requests             | 223185947           |

| Innodb_data_fsyncs                            | 1287541             |

| Innodb_data_pending_fsyncs                    | 0                   |

| Innodb_data_pending_reads                     | 0                   |

| Innodb_data_pending_writes                    | 0                   |

| Innodb_data_read                              | 1475563520          |

| Innodb_data_reads                             | 90656               |

| Innodb_data_writes                            | 2483930             |

| Innodb_data_written                           | 53829655552         |

| Innodb_dblwr_pages_written                    | 1348133             |

| Innodb_dblwr_writes                           | 52495               |

| Innodb_have_atomic_builtins                   | ON                  |

| Innodb_log_waits                              | 0                   |

//不為0,增加redo_log_buffer_size 的大小

| Innodb_log_write_requests                     | 20236030            |

| Innodb_log_writes                             | 1050665             |

| Innodb_os_log_fsyncs                          | 1061753             |

| Innodb_os_log_pending_fsyncs                  | 0                   |

| Innodb_os_log_pending_writes                  | 0                   |

| Innodb_os_log_written                         | 9647985152          |

| Innodb_page_size                              | 16384               |

| Innodb_pages_created                          | 402005              |

| Innodb_pages_read                             | 90056               |

| Innodb_pages_written                          | 1348133             |

| Innodb_row_lock_current_waits                 | 0                   |

| Innodb_row_lock_time                          | 508                 |

| Innodb_row_lock_time_avg                      | 127                 |

| Innodb_row_lock_time_max                      | 220                 |

| Innodb_row_lock_waits                         | 4                   |

//當前等待行鎖的數量

| Innodb_rows_deleted                           | 450897              |

| Innodb_rows_inserted                          | 47670586            |

| Innodb_rows_read                              | 2067494266811       |

| Innodb_rows_updated                           | 559293              |

| Innodb_num_open_files                         | 262                 |

| Innodb_truncated_status_writes                | 0                   |

| Innodb_available_undo_logs                    | 128                 |

| Key_blocks_not_flushed                        | 0                   |

| Key_blocks_unused                             | 0                   |

| Key_blocks_used                               | 6698                |

| Key_read_requests                             | 1125072100          |

| Key_reads                                     | 196951              |

| Key_write_requests                            | 294293748           |

| Key_writes                                    | 1272202             |

| Last_query_cost                               | 0.000000            |

| Last_query_partial_plans                      | 0                   |

| Max_used_connections                          | 115                 |

| Not_flushed_delayed_rows                      | 0                   |

| Open_files                                    | 1310                |

| Open_streams                                  | 0                   |

| Open_table_definitions                        | 922                 |

| Open_tables                                   | 1084                | //當前開啟表數量

| Opened_files                                  | 106007              |

| Opened_table_definitions                      | 2362                |

| Opened_tables                                 | 2326                |//已經開啟表的數量,數值非常大,table_open_cache值太小,

| 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_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_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_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                            | 1031352             |

| Qcache_hits                                   | 0                   |

| Qcache_inserts                                | 0                   |

| Qcache_lowmem_prunes                          | 0                   |

| Qcache_not_cached                             | 30592784            |

| Qcache_queries_in_cache                       | 0                   |

| Qcache_total_blocks                           | 1                   |

| Queries                                       | 68742245            |

| Questions                                     | 67444341            |

| Rpl_semi_sync_master_clients                  | 2                   |

| Rpl_semi_sync_master_net_avg_wait_time        | 16666               |

| Rpl_semi_sync_master_net_wait_time            | 16396467002         |

| Rpl_semi_sync_master_net_waits                | 983773              |

| Rpl_semi_sync_master_no_times                 | 1                   |

| Rpl_semi_sync_master_no_tx                    | 72385               |

| Rpl_semi_sync_master_status                   | ON                  |

| Rpl_semi_sync_master_timefunc_failures        | 0                   |

| Rpl_semi_sync_master_tx_avg_wait_time         | 971                 |

| Rpl_semi_sync_master_tx_wait_time             | 516125598           |

| Rpl_semi_sync_master_tx_waits                 | 531060              |

| Rpl_semi_sync_master_wait_pos_backtraverse    | 0                   |

| Rpl_semi_sync_master_wait_sessions            | 0                   |

| Rpl_semi_sync_master_yes_tx                   | 531163              |

| Select_full_join                              | 4643                |

| Select_full_range_join                        | 1531                |

| Select_range                                  | 5638901             |

| Select_range_check                            | 0                   |

| Select_scan                                   | 1530785             |

| Slave_heartbeat_period