MySQL 5.6所有系統變數(系統引數)

lhrbest發表於2017-03-22

MySQL 5.6所有系統變數




地址:https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html





5.1.5 Server System Variables

The MySQL server maintains many system variables that indicate how it is configured. Each system variable has a default value. System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically at runtime using the SET statement, which enables you to modify operation of the server without having to stop and restart it. Setting the global value of a system variable requires the SUPER privilege. For some system variables, setting the session value also requires the SUPER privilege; if so, it is indicated in the variable description. You can also use system variable values in expressions.

There are several ways to see the names and values of system variables:

  • To see the values that a server will use based on its compiled-in defaults and any option files that it reads, use this command:

    mysqld --verbose --help
    
  • To see the values that a server will use based on its compiled-in defaults, ignoring the settings in any option files, use this command:

    mysqld --no-defaults --verbose --help
    
  • To see the current values used by a running server, use the SHOW VARIABLES statement.

This section includes a table that lists all system variables and following the table provides a description of each one. Variables with no version indicated are present in all MySQL 5.6 releases. For more information about manipulation of system variables, seeSection 5.1.6, “Using System Variables”.

Table 5.3 System Variable Summary

Name Cmd-Line Option File System Var Var Scope Dynamic
audit_log_buffer_size Yes Yes Yes Global No
audit_log_connection_policy Yes Yes Yes Global Yes
audit_log_current_session     Yes Both No
audit_log_exclude_accounts Yes Yes Yes Global Yes
audit_log_file Yes Yes Yes Global No
audit_log_flush     Yes Global Yes
audit_log_format Yes Yes Yes Global No
audit_log_include_accounts Yes Yes Yes Global Yes
audit_log_policy Yes Yes Yes Global Varies
audit_log_rotate_on_size Yes Yes Yes Global Yes
audit_log_statement_policy Yes Yes Yes Global Yes
audit_log_strategy Yes Yes Yes Global No
auto_increment_increment     Yes Both Yes
auto_increment_offset     Yes Both Yes
autocommit Yes Yes Yes Both Yes
automatic_sp_privileges     Yes Global Yes
avoid_temporal_upgrade Yes Yes Yes Global Yes
back_log     Yes Global No
basedir Yes Yes Yes Global No
big-tables Yes Yes     Yes
Variablebig_tables     Yes Both Yes
bind-address Yes Yes     No
Variablebind_address     Yes Global No
binlog_cache_size Yes Yes Yes Global Yes
binlog_checksum     Yes Global Yes
binlog_direct_non_transactional_updates Yes Yes Yes Both Yes
binlog_error_action Yes Yes Yes Both Yes
binlog-format Yes Yes     Yes
Variablebinlog_format     Yes Both Yes
binlog_gtid_simple_recovery Yes Yes Yes Global No
binlog_max_flush_queue_time     Yes Global Yes
binlog_order_commits     Yes Global Yes
binlog_row_image Yes Yes Yes Both Yes
binlog_rows_query_log_events     Yes Both Yes
binlog_stmt_cache_size Yes Yes Yes Global Yes
binlogging_impossible_mode Yes Yes Yes Both Yes
block_encryption_mode Yes Yes Yes Both Yes
bulk_insert_buffer_size Yes Yes Yes Both Yes
character_set_client     Yes Both Yes
character_set_connection     Yes Both Yes
character_set_database[a]     Yes Both Yes
character-set-filesystem Yes Yes     Yes
Variablecharacter_set_filesystem     Yes Both Yes
character_set_results     Yes Both Yes
character-set-server Yes Yes     Yes
Variablecharacter_set_server     Yes Both Yes
character_set_system     Yes Global No
character-sets-dir Yes Yes     No
Variablecharacter_sets_dir     Yes Global No
collation_connection     Yes Both Yes
collation_database[b]     Yes Both Yes
collation-server Yes Yes     Yes
Variablecollation_server     Yes Both Yes
completion_type Yes Yes Yes Both Yes
concurrent_insert Yes Yes Yes Global Yes
connect_timeout Yes Yes Yes Global Yes
connection_control_failed_connections_threshold Yes Yes Yes Global Yes
connection_control_max_connection_delay Yes Yes Yes Global Yes
connection_control_min_connection_delay Yes Yes Yes Global Yes
core_file     Yes Global No
create_old_temporals Yes Yes Yes Global No
daemon_memcached_enable_binlog Yes Yes Yes Global No
daemon_memcached_engine_lib_name Yes Yes Yes Global No
daemon_memcached_engine_lib_path Yes Yes Yes Global No
daemon_memcached_option Yes Yes Yes Global No
daemon_memcached_r_batch_size Yes Yes Yes Global No
daemon_memcached_w_batch_size Yes Yes Yes Global No
datadir Yes Yes Yes Global No
date_format     Yes Global No
datetime_format     Yes Global No
debug Yes Yes Yes Both Yes
debug_sync     Yes Session Yes
default-storage-engine Yes Yes     Yes
Variabledefault_storage_engine     Yes Both Yes
default_tmp_storage_engine Yes Yes Yes Both Yes
default_week_format Yes Yes Yes Both Yes
delay-key-write Yes Yes     Yes
Variabledelay_key_write     Yes Global Yes
delayed_insert_limit Yes Yes Yes Global Yes
delayed_insert_timeout Yes Yes Yes Global Yes
delayed_queue_size Yes Yes Yes Global Yes
disable-gtid-unsafe-statements Yes Yes Yes Global No
disable_gtid_unsafe_statements Yes Yes Yes Global No
disconnect_on_expired_password Yes Yes Yes Session No
div_precision_increment Yes Yes Yes Both Yes
end_markers_in_json     Yes Both Yes
enforce-gtid-consistency Yes Yes Yes Global No
enforce_gtid_consistency Yes Yes Yes Global No
engine-condition-pushdown Yes Yes     Yes
Variableengine_condition_pushdown     Yes Both Yes
eq_range_index_dive_limit     Yes Both Yes
error_count     Yes Session No
event-scheduler Yes Yes     Yes
Variableevent_scheduler     Yes Global Yes
expire_logs_days Yes Yes Yes Global Yes
explicit_defaults_for_timestamp Yes Yes Yes Both Yes
external_user     Yes Session No
flush Yes Yes Yes Global Yes
flush_time Yes Yes Yes Global Yes
foreign_key_checks     Yes Both Yes
ft_boolean_syntax Yes Yes Yes Global Yes
ft_max_word_len Yes Yes Yes Global No
ft_min_word_len Yes Yes Yes Global No
ft_query_expansion_limit Yes Yes Yes Global No
ft_stopword_file Yes Yes Yes Global No
general-log Yes Yes     Yes
Variablegeneral_log     Yes Global Yes
general_log_file Yes Yes Yes Global Yes
group_concat_max_len Yes Yes Yes Both Yes
gtid_done     Yes Both No
gtid_executed     Yes Both No
gtid_lost     Yes Global No
gtid-mode Yes Yes     No
Variablegtid_mode     Yes Global No
gtid_mode     Yes Global No
gtid_next     Yes Session Yes
gtid_owned     Yes Both No
gtid_purged     Yes Global Yes
have_compress     Yes Global No
have_crypt     Yes Global No
have_csv     Yes Global No
have_dynamic_loading     Yes Global No
have_geometry     Yes Global No
have_innodb     Yes Global No
have_ndbcluster     Yes Global No
have_openssl     Yes Global No
have_partitioning     Yes Global No
have_profiling     Yes Global No
have_query_cache     Yes Global No
have_rtree_keys     Yes Global No
have_ssl     Yes Global No
have_symlink     Yes Global No
host_cache_size     Yes Global Yes
hostname     Yes Global No
identity     Yes Session Yes
ignore-builtin-innodb Yes Yes     No
Variableignore_builtin_innodb     Yes Global No
ignore_db_dirs     Yes Global No
init_connect Yes Yes Yes Global Yes
init-file Yes Yes     No
Variableinit_file     Yes Global No
init_slave Yes Yes Yes Global Yes
innodb_adaptive_flushing Yes Yes Yes Global Yes
innodb_adaptive_flushing_lwm Yes Yes Yes Global Yes
innodb_adaptive_hash_index Yes Yes Yes Global Yes
innodb_adaptive_max_sleep_delay Yes Yes Yes Global Yes
innodb_additional_mem_pool_size Yes Yes Yes Global No
innodb_api_bk_commit_interval Yes Yes Yes Global Yes
innodb_api_disable_rowlock Yes Yes Yes Global No
innodb_api_enable_binlog Yes Yes Yes Global No
innodb_api_enable_mdl Yes Yes Yes Global No
innodb_api_trx_level Yes Yes Yes Global Yes
innodb_autoextend_increment Yes Yes Yes Global Yes
innodb_autoinc_lock_mode Yes Yes Yes Global No
innodb_buffer_pool_dump_at_shutdown Yes Yes Yes Global Yes
innodb_buffer_pool_dump_now Yes Yes Yes Global Yes
innodb_buffer_pool_filename Yes Yes Yes Global Yes
innodb_buffer_pool_instances Yes Yes Yes Global No
innodb_buffer_pool_load_abort Yes Yes Yes Global Yes
innodb_buffer_pool_load_at_startup Yes Yes Yes Global No
innodb_buffer_pool_load_now Yes Yes Yes Global Yes
innodb_buffer_pool_size Yes Yes Yes Global No
innodb_change_buffer_max_size Yes Yes Yes Global Yes
innodb_change_buffering Yes Yes Yes Global Yes
innodb_change_buffering_debug Yes Yes Yes Global Yes
innodb_checksum_algorithm Yes Yes Yes Global Yes
innodb_checksums Yes Yes Yes Global No
innodb_cmp_per_index_enabled Yes Yes Yes Global Yes
innodb_commit_concurrency Yes Yes Yes Global Yes
innodb_compression_failure_threshold_pct Yes Yes Yes Global Yes
innodb_compression_level Yes Yes Yes Global Yes
innodb_compression_pad_pct_max Yes Yes Yes Global Yes
innodb_concurrency_tickets Yes Yes Yes Global Yes
innodb_data_file_path Yes Yes Yes Global No
innodb_data_home_dir Yes Yes Yes Global No
innodb_disable_sort_file_cache Yes Yes Yes Global Yes
innodb_doublewrite Yes Yes Yes Global No
innodb_fast_shutdown Yes Yes Yes Global Yes
innodb_fil_make_page_dirty_debug Yes Yes Yes Global Yes
innodb_file_format Yes Yes Yes Global Yes
innodb_file_format_check Yes Yes Yes Global No
innodb_file_format_max Yes Yes Yes Global Yes
innodb_file_per_table Yes Yes Yes Global Yes
innodb_flush_log_at_timeout     Yes Global Yes
innodb_flush_log_at_trx_commit Yes Yes Yes Global Yes
innodb_flush_method Yes Yes Yes Global No
innodb_flush_neighbors Yes Yes Yes Global Yes
innodb_flushing_avg_loops Yes Yes Yes Global Yes
innodb_force_load_corrupted Yes Yes Yes Global No
innodb_force_recovery Yes Yes Yes Global No
innodb_ft_aux_table     Yes Global Yes
innodb_ft_cache_size Yes Yes Yes Global No
innodb_ft_enable_diag_print Yes Yes Yes Global Yes
innodb_ft_enable_stopword Yes Yes Yes Global Yes
innodb_ft_max_token_size Yes Yes Yes Global No
innodb_ft_min_token_size Yes Yes Yes Global No
innodb_ft_num_word_optimize Yes Yes Yes Global Yes
innodb_ft_result_cache_limit Yes Yes Yes Global Yes
innodb_ft_server_stopword_table Yes Yes Yes Global Yes
innodb_ft_sort_pll_degree Yes Yes Yes Global No
innodb_ft_total_cache_size Yes Yes Yes Global No
innodb_ft_user_stopword_table Yes Yes Yes Both Yes
innodb_io_capacity Yes Yes Yes Global Yes
innodb_io_capacity_max Yes Yes Yes Global Yes
innodb_large_prefix Yes Yes Yes Global Yes
innodb_limit_optimistic_insert_debug Yes Yes Yes Global Yes
innodb_lock_wait_timeout Yes Yes Yes Both Yes
innodb_locks_unsafe_for_binlog Yes Yes Yes Global No
innodb_log_buffer_size Yes Yes Yes Global No
innodb_log_compressed_pages Yes Yes Yes Global Yes
innodb_log_file_size Yes Yes Yes Global No
innodb_log_files_in_group Yes Yes Yes Global No
innodb_log_group_home_dir Yes Yes Yes Global No
innodb_lru_scan_depth Yes Yes Yes Global Yes
innodb_max_dirty_pages_pct Yes Yes Yes Global Yes
innodb_max_dirty_pages_pct_lwm Yes Yes Yes Global Yes
innodb_max_purge_lag Yes Yes Yes Global Yes
innodb_max_purge_lag_delay Yes Yes Yes Global Yes
innodb_mirrored_log_groups Yes Yes Yes Global No
innodb_monitor_disable Yes Yes Yes Global Yes
innodb_monitor_enable Yes Yes Yes Global Yes
innodb_monitor_reset Yes Yes Yes Global Yes
innodb_monitor_reset_all Yes Yes Yes Global Yes
innodb_numa_interleave Yes Yes Yes Global No
innodb_old_blocks_pct Yes Yes Yes Global Yes
innodb_old_blocks_time Yes Yes Yes Global Yes
innodb_online_alter_log_max_size Yes Yes Yes Global Yes
innodb_open_files Yes Yes Yes Global No
innodb_optimize_fulltext_only Yes Yes Yes Global Yes
innodb_page_size Yes Yes Yes Global No
innodb_print_all_deadlocks Yes Yes Yes Global Yes
innodb_purge_batch_size Yes Yes Yes Global Yes
innodb_purge_threads Yes Yes Yes Global No
innodb_random_read_ahead Yes Yes Yes Global Yes
innodb_read_ahead_threshold Yes Yes Yes Global Yes
innodb_read_io_threads Yes Yes Yes Global No
innodb_read_only Yes Yes Yes Global No
innodb_replication_delay Yes Yes Yes Global Yes
innodb_rollback_on_timeout Yes Yes Yes Global No
innodb_rollback_segments Yes Yes Yes Global Yes
innodb_saved_page_number_debug Yes Yes Yes Global Yes
innodb_sort_buffer_size Yes Yes Yes Global No
innodb_spin_wait_delay Yes Yes Yes Global Yes
innodb_stats_auto_recalc Yes Yes Yes Global Yes
innodb_stats_include_delete_marked Yes Yes Yes Global Yes
innodb_stats_method Yes Yes Yes Global Yes
innodb_stats_on_metadata Yes Yes Yes Global Yes
innodb_stats_persistent Yes Yes Yes Global Yes
innodb_stats_persistent_sample_pages Yes Yes Yes Global Yes
innodb_stats_sample_pages Yes Yes Yes Global Yes
innodb_stats_transient_sample_pages Yes Yes Yes Global Yes
innodb_status_output Yes Yes Yes Global Yes
innodb_status_output_locks Yes Yes Yes Global Yes
innodb_strict_mode Yes Yes Yes Both Yes
innodb_support_xa Yes Yes Yes Both Yes
innodb_sync_array_size Yes Yes Yes Global No
innodb_sync_spin_loops Yes Yes Yes Global Yes
innodb_table_locks Yes Yes Yes Both Yes
innodb_thread_concurrency Yes Yes Yes Global Yes
innodb_thread_sleep_delay Yes Yes Yes Global Yes
innodb_tmpdir Yes Yes Yes Both Yes
innodb_trx_purge_view_update_only_debug Yes Yes Yes Global Yes
innodb_trx_rseg_n_slots_debug Yes Yes Yes Global Yes
innodb_undo_directory Yes Yes Yes Global No
innodb_undo_logs Yes Yes Yes Global Yes
innodb_undo_tablespaces Yes Yes Yes Global No
innodb_use_native_aio Yes Yes Yes Global No
innodb_use_sys_malloc Yes Yes Yes Global No
innodb_version     Yes Global No
innodb_write_io_threads Yes Yes Yes Global No
insert_id     Yes Session Yes
interactive_timeout Yes Yes Yes Both Yes
join_buffer_size Yes Yes Yes Both Yes
keep_files_on_create Yes Yes Yes Both Yes
key_buffer_size Yes Yes Yes Global Yes
key_cache_age_threshold Yes Yes Yes Global Yes
key_cache_block_size Yes Yes Yes Global Yes
key_cache_division_limit Yes Yes Yes Global Yes
language Yes Yes Yes Global No
large_files_support     Yes Global No
large_page_size     Yes Global No
large-pages Yes Yes     No
Variablelarge_pages     Yes Global No
last_insert_id     Yes Session Yes
lc-messages Yes Yes     Yes
Variablelc_messages     Yes Both Yes
lc-messages-dir Yes Yes     No
Variablelc_messages_dir     Yes Global No
lc_time_names     Yes Both Yes
license     Yes Global No
local_infile     Yes Global Yes
lock_wait_timeout Yes Yes Yes Both Yes
locked_in_memory     Yes Global No
log Yes Yes Yes Global Yes
log-bin Yes Yes Yes Global No
log_bin     Yes Global No
log_bin_basename     Yes Global No
log_bin_index     Yes Global No
log-bin-trust-function-creators Yes Yes     Yes
Variablelog_bin_trust_function_creators     Yes Global Yes
log-bin-use-v1-row-events Yes Yes     No
Variablelog_bin_use_v1_row_events     Yes Global No
log_bin_use_v1_row_events Yes Yes Yes Global No
log-error Yes Yes     No
Variablelog_error     Yes Global No
log-output Yes Yes     Yes
Variablelog_output     Yes Global Yes
log-queries-not-using-indexes Yes Yes     Yes
Variablelog_queries_not_using_indexes     Yes Global Yes
log-slave-updates Yes Yes     No
Variablelog_slave_updates     Yes Global No
log_slave_updates Yes Yes Yes Global No
log_slow_admin_statements     Yes Global Yes
log-slow-queries Yes Yes     Yes
Variablelog_slow_queries     Yes Global Yes
log_slow_slave_statements     Yes Global Yes
log_throttle_queries_not_using_indexes     Yes Global Yes
log-warnings Yes Yes     Yes
Variablelog_warnings     Yes Varies Yes
long_query_time Yes Yes Yes Both Yes
low-priority-updates Yes Yes     Yes
Variablelow_priority_updates     Yes Both Yes
lower_case_file_system     Yes Global No
lower_case_table_names Yes Yes Yes Global No
master_info_repository Yes Yes Yes Global Yes
master_verify_checksum     Yes Global Yes
max_allowed_packet Yes Yes Yes Both Yes
max_binlog_cache_size Yes Yes Yes Global Yes
max_binlog_size Yes Yes Yes Global Yes
max_binlog_stmt_cache_size Yes Yes Yes Global Yes
max_connect_errors Yes Yes Yes Global Yes
max_connections Yes Yes Yes Global Yes
max_delayed_threads Yes Yes Yes Both Yes
max_digest_length Yes Yes Yes Global No
max_error_count Yes Yes Yes Both Yes
max_heap_table_size Yes Yes Yes Both Yes
max_insert_delayed_threads     Yes Both Yes
max_join_size Yes Yes Yes Both Yes
max_length_for_sort_data Yes Yes Yes Both Yes
max_prepared_stmt_count Yes Yes Yes Global Yes
max_relay_log_size Yes Yes Yes Global Yes
max_seeks_for_key Yes Yes Yes Both Yes
max_sort_length Yes Yes Yes Both Yes
max_sp_recursion_depth Yes Yes Yes Both Yes
max_tmp_tables     Yes Both Yes
max_user_connections Yes Yes Yes Both Yes
max_write_lock_count Yes Yes Yes Global Yes
metadata_locks_cache_size     Yes Global No
metadata_locks_hash_instances     Yes Global No
min-examined-row-limit Yes Yes Yes Both Yes
multi_range_count Yes Yes Yes Both Yes
myisam_data_pointer_size Yes Yes Yes Global Yes
myisam_max_sort_file_size Yes Yes Yes Global Yes
myisam_mmap_size Yes Yes Yes Global No
myisam_recover_options     Yes Global No
myisam_repair_threads Yes Yes Yes Both Yes
myisam_sort_buffer_size Yes Yes Yes Both Yes
myisam_stats_method Yes Yes Yes Both Yes
myisam_use_mmap Yes Yes Yes Global Yes
mysql_firewall_max_query_size Yes Yes Yes Global No
mysql_firewall_mode Yes Yes Yes Global Yes
mysql_firewall_trace Yes Yes Yes Global Yes
named_pipe     Yes Global No
ndb_autoincrement_prefetch_sz Yes Yes Yes Both Yes
ndb-batch-size Yes Yes Yes Global No
ndb-blob-read-batch-bytes Yes Yes Yes Both Yes
ndb-blob-write-batch-bytes Yes Yes Yes Both Yes
ndb_cache_check_time Yes Yes Yes Global Yes
ndb_clear_apply_status Yes   Yes Global Yes
ndb-cluster-connection-pool Yes Yes Yes Global No
Ndb_conflict_last_conflict_epoch     Yes Global No
ndb-deferred-constraints Yes Yes     Yes
Variablendb_deferred_constraints     Yes Both Yes
ndb_deferred_constraints Yes Yes Yes Both Yes
ndb-distribution Yes Yes     Yes
Variablendb_distribution     Yes Global Yes
ndb_distribution Yes Yes Yes Global Yes
ndb_eventbuffer_free_percent Yes Yes Yes Global Yes
ndb_eventbuffer_max_alloc Yes Yes Yes Global Yes
ndb_extra_logging Yes Yes Yes Global Yes
ndb_force_send Yes Yes Yes Both Yes
ndb_index_stat_cache_entries Yes Yes Yes Both Yes
ndb_index_stat_enable Yes Yes Yes Both Yes
ndb_index_stat_option Yes Yes Yes Both Yes
ndb_index_stat_update_freq Yes Yes Yes Both Yes
ndb_join_pushdown     Yes Both Yes
ndb-log-apply-status Yes Yes     No
Variablendb_log_apply_status     Yes Global No
ndb_log_apply_status Yes Yes Yes Global No
ndb_log_bin Yes   Yes Both Yes
ndb_log_binlog_index Yes   Yes Global Yes
ndb-log-empty-epochs Yes Yes Yes Global Yes
ndb_log_empty_epochs Yes Yes Yes Global Yes
ndb-log-empty-update Yes Yes Yes Global Yes
ndb_log_empty_update Yes Yes Yes Global Yes
ndb-log-exclusive-reads Yes Yes     Yes
Variablendb_log_exclusive_reads     Yes Both Yes
ndb_log_exclusive_reads Yes Yes Yes Both Yes
ndb-log-orig Yes Yes     No
Variablendb_log_orig     Yes Global No
ndb_log_orig Yes Yes Yes Global No
ndb-log-transaction-id Yes Yes     No
Variablendb_log_transaction_id     Yes Global No
ndb_log_transaction_id     Yes Global No
ndb-log-update-as-write Yes Yes Yes Global Yes
ndb_log_updated_only Yes Yes Yes Global Yes
ndb_optimization_delay     Yes Global Yes
ndb_optimized_node_selection Yes Yes Yes Global No
ndb_recv_thread_cpu_mask     Yes Global Yes
ndb_report_thresh_binlog_epoch_slip Yes Yes Yes Global Yes
ndb_report_thresh_binlog_mem_usage Yes Yes Yes Global Yes
ndb_show_foreign_key_mock_tables Yes Yes Yes Global Yes
ndb_slave_conflict_role Yes Yes Yes Global Yes
Ndb_slave_max_replicated_epoch     Yes Global No
ndb_table_no_logging     Yes Session Yes
ndb_table_temporary     Yes Session Yes
ndb_use_copying_alter_table     Yes Both No
ndb_use_exact_count     Yes Both Yes
ndb_use_transactions Yes Yes Yes Both Yes
ndb_version     Yes Global No
ndb_version_string     Yes Global No
ndb-wait-connected Yes Yes Yes Global No
ndb-wait-setup Yes Yes Yes Global No
ndbinfo_database     Yes Global No
ndbinfo_max_bytes Yes   Yes Both Yes
ndbinfo_max_rows Yes   Yes Both Yes
ndbinfo_offline     Yes Global Yes
ndbinfo_show_hidden Yes   Yes Both Yes
ndbinfo_table_prefix Yes   Yes Both Yes
ndbinfo_version     Yes Global No
net_buffer_length Yes Yes Yes Both Yes
net_read_timeout Yes Yes Yes Both Yes
net_retry_count Yes Yes Yes Both Yes
net_write_timeout Yes Yes Yes Both Yes
new Yes Yes Yes Both Yes
old Yes Yes Yes Global No
old-alter-table Yes Yes     Yes
Variableold_alter_table     Yes Both Yes
old_passwords     Yes Both Yes
open-files-limit Yes Yes     No
Variableopen_files_limit     Yes Global No
optimizer_join_cache_level Yes Yes Yes Both Yes
optimizer_prune_level Yes Yes Yes Both Yes
optimizer_search_depth Yes Yes Yes Both Yes
optimizer_switch Yes Yes Yes Both Yes
optimizer_trace     Yes Both Yes
optimizer_trace_features     Yes Both Yes
optimizer_trace_limit     Yes Both Yes
optimizer_trace_max_mem_size     Yes Both Yes
optimizer_trace_offset     Yes Both Yes
performance_schema Yes Yes Yes Global No
performance_schema_accounts_size Yes Yes Yes Global No
performance_schema_digests_size Yes Yes Yes Global No
performance_schema_events_stages_history_long_size Yes Yes Yes Global No
performance_schema_events_stages_history_size Yes Yes Yes Global No
performance_schema_events_statements_history_long_size Yes Yes Yes Global No
performance_schema_events_statements_history_size Yes Yes Yes Global No
performance_schema_events_waits_history_long_size Yes Yes Yes Global No
performance_schema_events_waits_history_size Yes Yes Yes Global No
performance_schema_hosts_size Yes Yes Yes Global No
performance_schema_max_cond_classes Yes Yes Yes Global No
performance_schema_max_cond_instances Yes Yes Yes Global No
performance_schema_max_digest_length Yes Yes Yes Global No
performance_schema_max_file_classes Yes Yes Yes Global No
performance_schema_max_file_handles Yes Yes Yes Global No
performance_schema_max_file_instances Yes Yes Yes Global No
performance_schema_max_mutex_classes Yes Yes Yes Global No
performance_schema_max_mutex_instances Yes Yes Yes Global No
performance_schema_max_rwlock_classes Yes Yes Yes Global No
performance_schema_max_rwlock_instances Yes Yes Yes Global No
performance_schema_max_socket_classes Yes Yes Yes Global No
performance_schema_max_socket_instances Yes Yes Yes Global No
performance_schema_max_stage_classes Yes Yes Yes Global No
performance_schema_max_statement_classes Yes Yes Yes Global No
performance_schema_max_table_handles Yes Yes Yes Global No
performance_schema_max_table_instances Yes Yes Yes Global No
performance_schema_max_thread_classes Yes Yes Yes Global No
performance_schema_max_thread_instances Yes Yes Yes Global No
performance_schema_session_connect_attrs_size Yes Yes Yes Global No
performance_schema_setup_actors_size Yes Yes Yes Global No
performance_schema_setup_objects_size Yes Yes Yes Global No
performance_schema_users_size Yes Yes Yes Global No
pid-file Yes Yes     No
Variablepid_file     Yes Global No
plugin_dir Yes Yes Yes Global No
port Yes Yes Yes Global No
preload_buffer_size Yes Yes Yes Both Yes
profiling     Yes Both Yes
profiling_history_size Yes Yes Yes Both Yes
protocol_version     Yes Global No
proxy_user     Yes Session No
pseudo_slave_mode     Yes Session Yes
pseudo_thread_id     Yes Session Yes
query_alloc_block_size Yes Yes Yes Both Yes
query_cache_limit Yes Yes Yes Global Yes
query_cache_min_res_unit Yes Yes Yes Global Yes
query_cache_size Yes Yes Yes Global Yes
query_cache_type Yes Yes Yes Both Yes
query_cache_wlock_invalidate Yes Yes Yes Both Yes
query_prealloc_size Yes Yes Yes Both Yes
rand_seed1     Yes Session Yes
rand_seed2     Yes Session Yes
range_alloc_block_size Yes Yes Yes Both Yes
read_buffer_size Yes Yes Yes Both Yes
read_only Yes Yes Yes Global Yes
read_rnd_buffer_size Yes Yes Yes Both Yes
relay-log Yes Yes     No
Variablerelay_log     Yes Global No
relay_log_basename     Yes Global No
relay-log-index Yes Yes     No
Variablerelay_log_index     Yes Global No
relay_log_index Yes Yes Yes Global No
relay_log_info_file Yes Yes Yes Global No
relay_log_info_repository     Yes Global Yes
relay_log_purge Yes Yes Yes Global Yes
relay_log_recovery Yes Yes Yes Global Varies
relay_log_space_limit Yes Yes Yes Global No
report-host Yes Yes     No
Variablereport_host     Yes Global No
report-password Yes Yes     No
Variablereport_password     Yes Global No
report-port Yes Yes     No
Variablereport_port     Yes Global No
report-user Yes Yes     No
Variablereport_user     Yes Global No
rpl_semi_sync_master_enabled     Yes Global Yes
rpl_semi_sync_master_timeout     Yes Global Yes
rpl_semi_sync_master_trace_level     Yes Global Yes
rpl_semi_sync_master_wait_no_slave     Yes Global Yes
rpl_semi_sync_slave_enabled     Yes Global Yes
rpl_semi_sync_slave_trace_level     Yes Global Yes
rpl_stop_slave_timeout Yes Yes Yes Global Yes
secure-auth Yes Yes     Yes
Variablesecure_auth     Yes Global Yes
secure-file-priv Yes Yes     No
Variablesecure_file_priv     Yes Global No
server-id Yes Yes     Yes
Variableserver_id     Yes Global Yes
server-id-bits Yes Yes     No
Variableserver_id_bits     Yes Global No
server_id_bits Yes Yes Yes Global No
server_uuid     Yes Global No
sha256_password_private_key_path     Yes Global No
sha256_password_public_key_path     Yes Global No
shared_memory Yes Yes Yes Global No
shared_memory_base_name Yes Yes Yes Global No
show_old_temporals Yes Yes Yes Both Yes
simplified_binlog_gtid_recovery Yes Yes Yes Global No
skip_external_locking Yes Yes Yes Global No
skip-name-resolve Yes Yes     No
Variableskip_name_resolve     Yes Global No
skip-networking Yes Yes     No
Variableskip_networking     Yes Global No
skip-show-database Yes Yes     No
Variableskip_show_database     Yes Global No
slave_allow_batching Yes Yes Yes Global Yes
slave_checkpoint_group Yes Yes Yes Global Yes
slave_checkpoint_period Yes Yes Yes Global Yes
slave_compressed_protocol Yes Yes Yes Global Yes
slave_exec_mode Yes Yes Yes Global Yes
slave-load-tmpdir Yes Yes     No
Variableslave_load_tmpdir     Yes Global No
slave_max_allowed_packet     Yes Global Yes
slave-net-timeout Yes Yes     Yes
Variableslave_net_timeout     Yes Global Yes
slave_parallel_workers Yes   Yes Global Yes
slave_pending_jobs_size_max     Yes Global Yes
slave_rows_search_algorithms     Yes Global Yes
slave-skip-errors Yes Yes     No
Variableslave_skip_errors     Yes Global No
slave_sql_verify_checksum     Yes Global Yes
slave_transaction_retries Yes Yes Yes Global Yes
slave_type_conversions Yes Yes Yes Global No
slow_launch_time Yes Yes Yes Global Yes
slow-query-log Yes Yes     Yes
Variableslow_query_log     Yes Global Yes
slow_query_log_file Yes Yes Yes Global Yes
socket Yes Yes Yes Global No
sort_buffer_size Yes Yes Yes Both Yes
sql_auto_is_null     Yes Both Yes
sql_big_selects     Yes Both Yes
sql_big_tables     Yes Both Yes
sql_buffer_result     Yes Both Yes
sql_log_bin     Yes Session Yes
sql_log_off     Yes Both Yes
sql_low_priority_updates     Yes Both Yes
sql_max_join_size     Yes Both Yes
sql-mode Yes Yes     Yes
Variablesql_mode     Yes Both Yes
sql_notes     Yes Both Yes
sql_quote_show_create     Yes Both Yes
sql_safe_updates     Yes Both Yes
sql_select_limit     Yes Both Yes
sql_slave_skip_counter     Yes Global Yes
sql_warnings     Yes Both Yes
ssl-ca Yes Yes     No
Variablessl_ca     Yes Global No
ssl-capath Yes Yes     No
Variablessl_capath     Yes Global No
ssl-cert Yes Yes     No
Variablessl_cert     Yes Global No
ssl-cipher Yes Yes     No
Variablessl_cipher     Yes Global No
ssl-crl Yes Yes     No
Variablessl_crl     Yes Global No
ssl-crlpath Yes Yes     No
Variablessl_crlpath     Yes Global No
ssl-key Yes Yes     No
Variablessl_key     Yes Global No
storage_engine     Yes Both Yes
stored_program_cache Yes Yes Yes Global Yes
sync_binlog Yes Yes Yes Global Yes
sync_frm Yes Yes Yes Global Yes
sync_master_info Yes Yes Yes Global Yes
sync_relay_log Yes Yes Yes Global Yes
sync_relay_log_info Yes Yes Yes Global Yes
system_time_zone     Yes Global No
table_definition_cache     Yes Global Yes
table_open_cache     Yes Global Yes
table_open_cache_instances     Yes Global No
thread_cache_size Yes Yes Yes Global Yes
thread_concurrency Yes Yes Yes Global No
thread_handling Yes Yes Yes Global No
thread_pool_algorithm Yes Yes Yes Global No
thread_pool_high_priority_connection Yes Yes Yes Both Yes
thread_pool_max_unused_threads Yes Yes Yes Global Yes
thread_pool_prio_kickup_timer Yes Yes Yes Both Yes
thread_pool_size Yes Yes Yes Global No
thread_pool_stall_limit Yes Yes Yes Global Yes
thread_stack Yes Yes Yes Global No
time_format     Yes Global No
time_zone     Yes Both Yes
timed_mutexes Yes Yes Yes Global Yes
timestamp     Yes Session Yes
tmp_table_size Yes Yes Yes Both Yes
tmpdir Yes Yes Yes Global No
transaction_alloc_block_size Yes Yes Yes Both Yes
transaction_allow_batching     Yes Session Yes
transaction_prealloc_size Yes Yes Yes Both Yes
tx_isolation     Yes Both Yes
tx_read_only     Yes Both Yes
unique_checks     Yes Both Yes
updatable_views_with_limit Yes Yes Yes Both Yes
validate_password_dictionary_file     Yes Global Varies
validate_password_length     Yes Global Yes
validate_password_mixed_case_count     Yes Global Yes
validate_password_number_count     Yes Global Yes
validate_password_policy     Yes Global Yes
validate_password_special_char_count     Yes Global Yes
validate_user_plugins     Yes Global No
version     Yes Global No
version_comment     Yes Global No
version_compile_machine     Yes Global No
version_compile_os     Yes Global No
wait_timeout Yes Yes Yes Both Yes
warning_count     Yes Session No

[a] This option is dynamic, but only the server should set this information. You should not set the value of this variable manually.

[b] This option is dynamic, but only the server should set this information. You should not set the value of this variable manually.



For additional system variable information, see these sections:

Note

Some of the following variable descriptions refer to enabling or disabling a variable. These variables can be enabled with the SET statement by setting them to ON or 1, or disabled by setting them to OFF or 0. However, before MySQL 5.6.2, to set such a variable on the command line or in an option file, you must set it to 1 or 0; setting it to ON or OFF will not work. For example, on the command line, --delay_key_write=1 works but --delay_key_write=ON does not. As of MySQL 5.6.2, boolean variables can be set at startup to the values ONTRUEOFF, and FALSE (not case sensitive). See Section 4.2.5, “Program Option Modifiers”.




MySQL變數(引數)的檢視和設定



[MySQL] 變數(引數)的檢視和設定

 

類似於Oracle的引數檔案,MySQL的選項檔案(如my.cnf)用於配置MySQL伺服器,但和Oracle叫法不一樣,在MySQL裡, 官方叫變數(Varialbes),但其實叫引數也是可以的,只要明白這倆是同一個東西就可以了。

MySQL的變數分為以下兩種:

1)系統變數:配置MySQL伺服器的執行環境,可以用show variables檢視

2)狀態變數:監控MySQL伺服器的執行狀態,可以用show status檢視

 

系統變數

系統變數按其作用域的不同可以分為以下兩種:

1)分為全域性(GLOBAL)級:對整個MySQL伺服器有效

2)會話(SESSION或LOCAL)級:隻影響當前會話

有些變數同時擁有以上兩個級別,MySQL將在建立連線時用全域性級變數初始化會話級變數,但一旦連線建立之後,全域性級變數的改變不會影響到會話級變數。

檢視系統變數的值

可以通過show vairables語句檢視系統變數的值:

[sql] 

mysql> show variables like 'log%';  

mysql> show variables where Variable_name like 'log%' and value='ON';  

注意:show variables優先顯示會話級變數的值,如果這個值不存在,則顯示全域性級變數的值,當然你也可以加上GLOBAL或SESSION關鍵字區別:

[sql] 

show global variables;  

show session/local variables;  

在寫一些儲存過程時,可能需要引用系統變數的值,可以使用如下方法:

[sql] 

@@GLOBAL.var_name  

@@SESSION.var_name 或  

@@LOCAL.var_name  

如果在變數名前沒有級別限定符,將優先顯示會話級的值。

最後一種檢視變數值的方法是從INFORMATION_SCHEMA資料庫裡的GLOBAL_VARIABLES和SESSION_VARIABLES表獲得。

設定和修改系統變數的值

在MySQL伺服器啟動時,有以下兩種方法設定系統變數的值:

1)命令列引數,如:mysqld --max_connections=200

2)選項檔案(my.cnf)

在MySQL伺服器啟動後,如果需要修改系統變數的值,可以通過SET語句:

[plain] 

SET GLOBAL var_name = value;  

SET @@GLOBAL.var_name = value;  

SET SESSION var_name = value;  

SET @@SESSION.var_name = value;  

如果在變數名前沒有級別限定符,表示修改會話級變數。

注意:和啟動時不一樣的是,在執行時設定的變數不允許使用字尾字母'K'、‘M'等,但可以用表示式來達到相同的效果,如:

[sql] 

SET GLOBAL read_buffer_size = 2*1024*1024  

 

狀態變數

狀態變數可以使我們及時瞭解MySQL伺服器的執行狀況,可以使用show status語句檢視。

狀態變數和相同變數類似,也分為全域性級和會話級,show status也支援like匹配查詢,比較大的不同是狀態變數只能由MySQL伺服器本身設定和修改,對於使用者來說是隻讀的,不可以通過SET語句設定和修改它們。



當啟動例項時,MySQL資料庫會去讀取配置檔案,根據配置檔案的引數來啟動資料庫例項。這與Oracle的引數檔案(spfile)相似,不同的是,Oracle中如果沒有引數檔案,在啟動例項時會提示找不到該引數檔案,資料庫啟動失敗。而在MySQL資料庫中,可以沒有配置檔案,在這種情況下,MySQL會按照編譯時的預設引數設定啟動例項。用以下命令可以檢視當MySQL資料庫例項啟動時,會在哪些位置查詢配置檔案。

  1. [root@xen-server bin]# mysql --help | grep my.cnf  
  2. order of preference, my.cnf, $MYSQL_TCP_PORT,  
  3. /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 

可以看到,MySQL資料庫是按/etc/my.cnf→/etc/mysql/my.cnf→/usr/local/mysql/etc/my.cnf→~/.my.cnf的順序讀取配置檔案的。可能有讀者會問:“如果幾個配置檔案中都有同一個引數,MySQL資料庫以哪個配置檔案為準?”答案很簡單,MySQL資料庫會以讀取到的最後一個配置檔案中的引數為準。在Linux環境下,配置檔案一般放在/etc/my.cnf下。在Windows平臺下,配置檔案的字尾名可能是.cnf,也可能是.ini。例如在Windows作業系統下執行mysql--help,可以找到如下類似內容:

  1. Default options are read from the following files in the given order:  
  2. C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf C:\Program Files\MySQL\M  
  3. \MySQL Server 5.1\my.cnf 



ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.GLOBAL_STATUS' feature is disabled; see the documentation for 'show_compatibility_56'

  1. --從mysql5.7.6開始information_schema.global_status已經開始被捨棄,為了相容性,此時需要開啟 show_compatibility_56  
  2. mysql> select * from information_schema.global_status limit 3;  
  3. ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.GLOBAL_STATUS' feature is disabled; see the documentation for 'show_compatibility_56'  
  4.   
  5. --檢視show_compatibility_56其值  
  6. mysql> show variables like '%show_compatibility_56%';  
  7. +-----------------------+-------+  
  8. | Variable_name         | Value |  
  9. +-----------------------+-------+  
  10. | show_compatibility_56 | OFF   |  
  11. +-----------------------+-------+  
  12. 1 row in set (0.01 sec)  
  13.   
  14. --把show_compatibility_56開啟  
  15. mysql> set global show_compatibility_56=on;  
  16. Query OK, 0 rows affected (0.00 sec)  
  17.   
  18. mysql> show variables like '%show_compatibility_56%';  
  19. +-----------------------+-------+  
  20. | Variable_name         | Value |  
  21. +-----------------------+-------+  
  22. | show_compatibility_56 | ON    |  
  23. +-----------------------+-------+  
  24. 1 row in set (0.00 sec)  
  25.   
  26. mysql> select * from information_schema.global_status limit 3;  
  27. +-----------------------+----------------+  
  28. | VARIABLE_NAME         | VARIABLE_VALUE |  
  29. +-----------------------+----------------+  
  30. | ABORTED_CLIENTS       | 0              |  
  31. | ABORTED_CONNECTS      | 0              |  
  32. | BINLOG_CACHE_DISK_USE | 0              |  
  33. +-----------------------+----------------+  
  34. 3 rows in set, 1 warning (0.00 sec)  
  35.   
  36. In MySQL 5.6, system and status variable information is available from these SHOW statements:  
  37.   
  38. SHOW VARIABLES  
  39. SHOW STATUS  
  40. And from these INFORMATION_SCHEMA tables:  
  41. INFORMATION_SCHEMA.GLOBAL_VARIABLES  
  42. INFORMATION_SCHEMA.SESSION_VARIABLES  
  43. INFORMATION_SCHEMA.GLOBAL_STATUS  
  44. INFORMATION_SCHEMA.SESSION_STATUS  
  45.   
  46. MySQL 5.7  
  47. As of MySQL 5.7.6, the Performance Schema includes these tables as new sources of system and status  
  48. variable information:  
  49. performance_schema.global_variables  
  50. performance_schema.session_variables  
  51. performance_schema.variables_by_thread  
  52. performance_schema.global_status  
  53. performance_schema.session_status  
  54. performance_schema.status_by_thread  
  55. performance_schema.status_by_account  
  56. performance_schema.status_by_host  
  57. performance_schema.status_by_user  



MySQL 5.7資料庫引數優化



連線相關引數

max_connections:允許客戶端併發連線的最大數量,預設值是151,一般將該引數設定為500-2000


max_connect_errors:如果客戶端嘗試連線的錯誤數量超過這個引數設定的值,則伺服器不再接受新的客戶端連線。可以通過清空主機的快取來解除伺服器的這種阻止新連線的狀態,通過FLUSH HOSTS或mysqladmin flush-hosts命令來清空快取。這個引數的預設值是100,一般將該引數設定為100000。

interactive_timeout:Mysql關閉互動連線前的等待時間,單位是秒,預設是8小時,建議不要將該引數設定超過24小時,即86400

wait_timeout:Mysql關閉非互動連線前的等待時間,單位是秒,預設是8小時,建議不要將該引數設定超過24小時,即86400

skip_name_resolve:如果這個引數設為OFF,則MySQL服務在檢查客戶端連線的時候會解析主機名;如果這個引數設為ON,則MySQL服務只會使用IP,在這種情況下,授權表中的Host欄位必須是IP地址或localhost。
這個引數預設是關閉的

back_log:MySQL伺服器連線請求佇列所能處理的最大連線請求數,如果佇列放滿了,後續的連線才會拒絕。當主要的MySQL執行緒在很短時間內獲取大量連線請求時,這個引數會生效。接下來,MySQL主執行緒會花費很短的時間去檢查連線,然後開啟新的執行緒。這個引數指定了MySQL的TCP/IP監聽佇列的大小。如果MySQL伺服器在短時間內有大量的連線,可以增加這個引數。


檔案相關引數

sync_binlog:控制二進位制日誌被同步到磁碟前二進位制日誌提交組的數量。當這個引數為0的時候,二進位制日誌不會被同步到磁碟;當這個引數設為0以上的數值時,就會有設定該數值的二進位制提交組定期同步日誌到磁碟。當這個引數設為1的時候,所有事務在提交前會被同步到二進位制日誌中,因而即使MySQL伺服器發生意外重啟,任何二進位制日誌中沒有的事務只會處於準備狀態,這會導致MySQL伺服器自動恢復以回滾這些事務。這樣就會保證二進位制日誌不會丟失事務,是最安全的選項;同時由於增加了磁碟寫,這對效能有一定降低。將這個引數設為1以上的數值會提高資料庫的效能,但同時會伴隨資料丟失的風險。建議將該引數設為2、4、6、8、16。

expire_logs_days:二進位制日誌自動刪掉的時間間隔。預設值為0,代表不會自動刪除二進位制日誌。想手動刪除二進位制日誌,可以執行 PURGE BINARY LOGS。

max_binlog_size:二進位制日誌檔案的最大容量,當寫入的二進位制日誌超過這個值的時候,會完成當前二進位制的寫入,向新的二進位制日誌寫入日誌。這個引數最小值時4096位元組;最大值和預設值時1GB。相同事務中的語句都會寫入同一個二進位制日誌,當一個事務很大時,二進位制日誌實際的大小會超過max_binlog_size引數設定的值。如果max_relay_log_size引數設為0,則max_relay_log_size引數會使用和max_binlog_size引數同樣的大小。建議將此引數設為512M。

local_infile:是否允許客戶端使用LOAD DATA INFILE語句。如果這個引數沒有開啟,客戶端不能在LOAD DATA語句中使用LOCAL引數。

open_files_limit:作業系統允許MySQL服務開啟的檔案數量。這個引數實際的值以系統啟動時設定的值、max_connections和table_open_cache為基礎,使用下列的規則:

  1. 10 + max_connections + (table_open_cache * 2)

  2.  max_connections * 5

  3. MySQL啟動時指定open_files_limit的值


快取控制引數

binlog_cache_size:在事務中二進位制日誌使用的快取大小。如果MySQL伺服器支援所有的儲存引擎且啟用二進位制日誌,每個客戶端都會被分配一個二進位制日誌快取。如果資料庫中有很多大的事務,增大這個快取可以獲得更好的效能。


Binlog_cache_use和Binlog_cache_disk_use這兩個引數對於binlog_cache_size引數的優化很有用。binlog_cache_size引數只設定事務所使用的快取,非事務SQL語句所使用的快取由binlog_stmt_cache_size系統引數控制。建議不要將這個引數設為超過64MB,以防止客戶端連線多而影響MySQL服務的效能。

max_binlog_cache_size:如果一個事務需要的記憶體超過這個引數,伺服器會報錯"Multi-statement transaction required more than 'max_binlog_cache_size' bytes"。這個引數最大的推薦值是4GB,這是因為MySQL不能在二進位制日誌設為超過4GB的情況下正常的工作。建議將該引數設為binlog_cache_size*2。

binlog_stmt_cache_size:這個引數決定二進位制日誌處理非事務性語句的快取。如果MySQL服務支援任何事務性的儲存引擎且開啟了二進位制日誌,每個客戶端連線都會被分配二進位制日誌事務和語句快取。如果資料庫中經常執行大的事務,增加這個快取可以獲得更好的效能。

table_open_cache:所有執行緒能開啟的表的數量。

thread_cache_size:MySQL服務快取以重用的執行緒數。當客戶端斷開連線的時候,如果執行緒快取沒有使用滿,則客戶端的執行緒被放入快取中。如果有客戶端斷開連線後再次連線到MySQL服務且執行緒在快取中,則MySQL服務會優先使用快取中的執行緒;如果執行緒快取沒有這些執行緒,則MySQL伺服器會建立新的執行緒。如果資料庫有很多的新連線,可以增加這個引數來提升效能。如果MySQL伺服器每秒有上百個連線,可以增大thread_cache_size引數來使MySQL伺服器使用快取的執行緒。通過檢查Connections和Threads_created狀態引數,可以判斷執行緒快取是否足夠。這個引數預設的值是由下面的公式來決定的:

8 + (max_connections / 100)

建議將此引數設定為300~500。執行緒快取的命中率計算公式為(1-thread_created/connections)*100%,可以通過這個公式來優化和調整thread_cache_size引數。


query_cache_size:為查詢結果所分配的快取。預設這個引數是沒有開啟的。這個引數的值應設為整數的1024倍,如果設為其他值則會被自動調整為接近此數值的1024倍。這個引數最小需要40KB。建議不要將此引數設為大於256MB,以免佔用太多的系統記憶體。

query_cache_min_res_unit:查詢快取所分配的最小塊的大小。預設值是4096(4KB)。

query_cache_type:設定查詢快取的型別。當這個引數為0或OFF時,則MySQL伺服器不會啟用查詢快取;當這個引數為1或ON時,則MySQL伺服器會快取所有查詢結果(除了帶有SELECT SQL_NO_CACHE的語句);當這個引數為2或DEMAND時,則MySQL伺服器只會快取帶有SELECT SQL_CACHE的語句。

sort_buffer_size:每個會話執行排序操作所分配的記憶體大小。想要增大max_sort_length引數,需要增大sort_buffer_size引數。如果在SHOW GLOBAL STATUS輸出結果中看到每秒輸出的Sort_merge_passes狀態引數很大,可以考慮增大sort_buffer_size這個值來提高ORDER BY 和 GROUP BY的處理速度。建議設定為1~4MB。當個別會話需要執行大的排序操作時,在會話級別增大這個引數。

read_buffer_size:為每個執行緒對MyISAm表執行順序讀所分配的記憶體。如果資料庫有很多順序讀,可以增加這個引數,預設值是131072位元組。這個引數的值需要是4KB的整數倍。這個引數也用在下面場景中:

  • 當執行ORDER BY操作時,快取索引到臨時檔案(不是臨時表)中;

  • 執行批量插入到分割槽表中;

  • 快取巢狀查詢的執行結果。


read_rnd_buffer_size:這個引數用在MyISAM表和任何儲存引擎表隨機讀所使用的記憶體。當從MyISAM表中以鍵排序讀取資料的時候,掃描的行將使用這個快取以避免磁碟的掃描。將這個值設到一個較大的值可以顯著提升ORDER BY的效能。然後,這個引數會應用到所有的客戶端連線,所有不應該將這個引數在全域性級別設為一個較大的值;在執行大查詢的會話中,在會話級別增大這個引數即可。

join_buffer_size:MySQL伺服器用來作普通索引掃描、範圍索引掃描和不使用索引而執行全表掃描這些操作所用的快取大小。通常,獲取最快連線的方法是增加索引。當不能增加索引的時候,使全連線變快的方法是增大join_buffer_size引數。對於執行全連線的兩張表,每張表都被分配一塊連線記憶體。對於沒有使用索引的多表複雜連線,需要多塊連線記憶體。通常來說,可以將此引數在全域性上設定一個較小的值,而在需要執行大連線的會話中在會話級別進行設定。預設值是256KB。

net_buffer_length:每個客戶端執行緒和連線快取和結果快取互動,每個快取最初都被分配大小為net_buffer_length的容量,並動態增長,直至達到max_allowed_packet引數的大小。當每條SQL語句執行完畢後,結果快取會縮小到net_buffer_length大小。不建議更改這個引數,除非你的系統有很少的記憶體,可以調整這個引數。如果語句需要的記憶體超過了這個引數的大小,則連線快取會自動增大。net_buffer_length引數最大可以設定到1MB。不能在會話級別設定這個引數。

max_allowed_packet:網路傳輸時單個資料包的大小。預設值是4MB。包資訊快取的初始值是由net_buffer_length指定的,但是包可能會增長到max_allowed_packet引數設定的值。如果要使用BLOB欄位或長字串,需要增加這個引數的值。這個引數的值需要設定成和最大的BLOB欄位一樣的大小。max_allowed_packet引數的協議限制是1GB。這個引數應該是1024整數倍。

bulk_insert_buffer_size:MyISAM表使用一種特殊的樹狀快取來提高批量插入的速度,如INSERT ... SELECT,INSERT ... VALUES (...),(...), ...,對空表執行執行LOAD DATA INFILE。這個引數每個執行緒的樹狀快取大小。將這個引數設為0會關閉這個引數。這個引數的預設值是8MB。


max_heap_table_size:這個引數設定使用者建立的MEMORY表允許增長的最大容量,這個引數用來MEMORY表的MAX_ROWS值。設定這個引數對已有的MEMORY表沒有影響,除非表重建或執行ALTER TABLE、TRUNCATE TABLE語句。

這個引數也和tmp_table_size引數一起來現在內部in-memory表的大小。如果記憶體表使用頻繁,可以增大這個引數的值。

tmp_table_size:內部記憶體臨時表的最大記憶體。這個引數不會應用到使用者建立的MEMORY表。如果記憶體臨時表的大小超過了這個引數的值,則MySQL會自動將超出的部分轉化為磁碟上的臨時表。在MySQL 5.7.5版本,internal_tmp_disk_storage_engine儲存引擎將作為磁碟臨時表的預設引擎。在MySQL 5.7.5之前的版本,會使用MyISAM儲存引擎。如果有很多的GROUP BY查詢且系統記憶體充裕,可以考慮增大這個引數。

innodb_buffer_pool_dump_at_shutdown:指定在MySQL服務關閉時,是否記錄InnoDB快取池中的快取頁,以縮短下次重啟時的預熱過程。通常和innodb_buffer_pool_load_at_startup引數搭配使用。innodb_buffer_pool_dump_pct引數定義了保留的最近使用快取頁的百分比。

innodb_buffer_pool_dump_now:立刻記錄InnoDB緩衝池中的快取頁。通常和innodb_buffer_pool_load_now搭配使用。

innodb_buffer_pool_load_at_startup:指定MySQL服務在啟動時,InnoDB緩衝池通過載入之前的快取頁資料來自動預熱。通常和innodb_buffer_pool_dump_at_shutdown引數搭配使用。

innodb_buffer_pool_load_now:立刻通過載入資料頁來預熱InnoDB緩衝池,無需重啟資料庫服務。可以用來在效能測試時,將快取改成到一個已知的狀態;或在資料庫執行報表查詢或維護後,將資料庫改成到一個正常的狀態。


MyISAM引數

key_buffer_size:所有執行緒所共有的MyISAM表索引快取,這塊快取被索引塊使用。增大這個引數可以增加索引的讀寫效能,在主要使用MyISAM儲存引擎的系統中,可設定這個引數為機器總記憶體的25%。如果將這個引數設定很大,比如設為機器總記憶體的50%以上,機器會開始page且變得異常緩慢。可以通過SHOW STATUS 語句檢視 Key_read_requests,Key_reads,Key_write_requests, and Key_writes這些狀態值。正常情況下Key_reads/Key_read_requests 比率應該小於0.01。資料庫更新和刪除操作頻繁的時候,Key_writes/Key_write_requests 比率應該接近1。

key_cache_block_size:key快取的塊大小,預設值是1024位元組。

myisam_sort_buffer_size:在REPAIR TABLE、CREATE INDEX 或 ALTER TABLE操作中,MyISAM索引排序使用的快取大小。

myisam_max_sort_file_size:當重建MyISAM索引的時候,例如執行REPAIR TABLE、 ALTER TABLE、 或 LOAD DATA INFILE命令,MySQL允許使用的臨時檔案的最大容量。如果MyISAM索引檔案超過了這個值且磁碟還有充裕的空間,增大這個引數有助於提高效能。

myisam_repair_threads:如果這個引數的值大於1,則MyISAM表在執行Repair操作的排序過程中,在建立索引的時候會啟用並行,預設值為1。


InnoDB引數

innodb_buffer_pool_size:InnDB儲存引擎快取表和索引資料所使用的記憶體大小。預設值是128MB。在以InnDB儲存引擎為主的系統中,可以將這個引數設為機器實體記憶體的80%。同時需要注意:

  • 設定較大實體記憶體時是否會引擎頁的交換而導致效能下降;

  • InnoDB儲存引擎會為快取和控制表結構資訊使用部分記憶體,因而實際花費的記憶體會比設定的值大於10%;

  • 這個引數設定的越大,初始化記憶體池的時間越長。在MySQL 5.7.5版本,可以以chunk為單位增加或減少記憶體池的大小。chunk的大小可以通過innodb_buffer_pool_chunk_size引數設定,預設值是128MB。記憶體池的大小可以等於或是innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances的整數倍。


innodb_buffer_pool_instances:InnoDB快取池被分成的區域數。對於1GB以上大的InnoDB快取,將快取分成多個部分可以提高MySQL服務的併發性,減少不同執行緒讀快取頁的讀寫競爭。每個快取池有它單獨的空閒列表、重新整理列表、LRU列表和其他連線到記憶體池的資料結構,它們被mutex鎖保護。這個引數只有將innodb_buffer_pool_size引數設為1GB或以上時才生效。建議將每個分成的記憶體區域設為1GB大小。

innodb_max_dirty_pages_pct:當Innodb快取池中髒頁所佔的百分比達到這個引數的值時,InnoDB會從快取中向磁碟寫入資料。預設值是75。


innodb_thread_concurrency:InnoDB儲存引擎可以併發使用的最大執行緒數。當InnoDB使用的執行緒超過這引數的值時,後面的執行緒會進入等待狀態,以先進先出的演算法來處理。等待鎖的執行緒不計入這個引數的值。這個引數的範圍是0~1000。預設值是0。當這個引數為0時,代表InnoDB執行緒的併發數沒有限制,這樣會導致MySQL建立它所需要的儘可能多的執行緒。設定這個引數可以參考下面規則:

  • 如果使用者執行緒的併發數小於64,可以將這個引數設為0;

  • 如果系統併發很嚴重,可以先將這個引數設為128,然後再逐漸將這個引數減小到96, 80, 64或其他數值,直到找到效能較好的一個數值。


innodb_flush_method:指定重新整理資料到InnoDB資料檔案和日誌檔案的方法,重新整理方法會對I/O有影響。如果這個引數的值為空,在類Unix系統上,這個引數的預設值為fsync;在Windows系統上,這個引數的預設值為async_unbuffered。在類Unix系統上,這個引數可設定的值如下:

  • fsync:InnoDB使用fsync()系統函式來重新整理資料和日誌檔案,fsync是預設引數。

  • O_DSYNC:InnoDB使用O_SYNC函式來開啟和重新整理日誌檔案,使用fsync()函式重新整理資料檔案

  • littlesync:這個選項用在內部效能的測試,目前MySQL尚不支援,使用這個引數又一定的風險

  • nosync:這個選項用在內部效能的測試,目前MySQL尚不支援,使用這個引數又一定的風險

  • O_DIRECT:InnoDB使用O_DIRECT(或者directio()在Solaris)函式開啟資料檔案,使用fsync()重新整理資料檔案和日誌檔案

  • O_DIRECT_NO_FSYNC:在重新整理I/O時,InnoDB使用O_DIRECT方式。


在有RAID卡和寫快取的系統中,O_DIRECT有助於避免InnoDB快取池和作業系統快取之間的雙重快取。在InnoDB資料和日誌檔案放在SAN儲存上面的系統,預設值或O_DSYNC方法會對以讀為主的資料庫起到加速作用。


innodb_data_home_dir:InnoDB系統表空間所使用的資料檔案的物理路徑,預設路徑是MySQL資料檔案路徑。如果這個引數的值為空,可以在innodb_data_file_path引數裡使用絕對路徑

innodb_data_file_path:InnoDB資料檔案的路徑和大小。

innodb_file_per_table:當這個引數啟用的時候,InnoDB會將新建表的資料和索引單獨存放在.ibd格式的檔案中,而不是存放在系統表空間中。當這張表被刪除或TRUNCATE時,InnoDB表所佔用的儲存會被釋放。這個設定會開啟InnoDB的一些其他特性,比如表的壓縮。當這個引數關閉的時候,InnoDB會將表和索引的資料存放到系統表空間的ibdata檔案中,這會有一個問題,因為系統表空間不會縮小,這樣設定會導致空間無法回放。

innodb_undo_directory:InnoDB undo日誌所在表空間的物理路徑。和innodb_undo_logs、innodb_undo_tablespaces引數配合,來設定undo日誌的路徑,預設路徑是資料檔案路徑。

innodb_undo_logs:指定InnoDB使用的undo日誌的個數。在MySQL 5.7.2版本,32個undo日誌被臨時表預留使用,並且這些日誌存放在臨時表表空間(ibtmp1)中。如果undo日誌只存放在系統表空間中,想要額外分配供資料修改事務用的undo日誌,innodb_undo_logs引數必須設定為32以上的整數。如果你配置了單獨的undo表空間,要將innodb_undo_logs引數設為33以上來分配額外供資料修改事務使用的undo日誌。每個undo日誌最多可以支援1024個事務。如果這個引數沒有設定,則它會設為預設值128。

innodb_undo_tablespaces:undo日誌的表空間檔案數量。預設,所有的undo日誌都是系統表空間的一部分。因為在執行大的事務時,undo日誌會增大,將undo日誌設定在多個表空間中可以減少一個表空間的大小。undo表空間檔案建立在innodb_undo_directory引數指定的路徑下,以undoN格式命名,N是以0開頭的一系列整數。undo表空間的預設大小為10M。需要在初始化InnoDB前設定innodb_undo_tablespaces這個引數。在MySQL 5.7.2版本,在128個undo日誌中,有32個undo日誌是為臨時表所預留的,有95個undo日誌供undo表空間使用。

innodb_log_files_in_group:InnoDB日誌組包含的日誌個數。InnoDB以迴圈的方式寫入日誌。這個引數的預設值和推薦值均是2。日誌的路徑由innodb_log_group_home_dir引數設定。

innodb_log_group_home_dir:InnoDB重做日誌檔案的物理路徑,重做日誌的數量由innodb_log_files_in_group引數指定。如果不指定任何InnoDB日誌引數,MySQL預設會在MySQL資料檔案路徑下面建立兩個名為ib_logfile0、ib_logfile1的兩個重做日誌檔案,它們的大小由innodb_log_file_size引數設定。

innodb_log_file_size:日誌組中每個日誌檔案的位元組大小。所有日誌檔案的大小(innodb_log_file_size * innodb_log_files_in_group)不能超過512GB。

innodb_log_buffer_size:InnoDB寫入磁碟日誌檔案所使用的快取位元組大小。如果innodb_page_size引數為32K,則預設值是8MB;如果innodb_page_size引數為64K,則預設值是16MB。如果日誌的快取設定較大,則MySQL在處理大事務時,在提交事務前無需向磁碟寫入日誌檔案。建議設定此引數為4~8MB。

innodb_flush_log_at_trx_commit:當提交相關的I/O操作被批量重新排列時,這個引數控制提交操作的ACID一致性和高效能之間的平衡。可以改變這個引數的預設值來提升資料庫的效能,但是在資料庫當機的時候會丟失少量的事務。這個引數的預設值為1,代表資料庫遵照完整的ACID模型,每當事務提交時,InnoDB日誌快取中的內容均會被重新整理到日誌檔案,並寫入到磁碟。當這個引數為0時,InnDB日誌快取大概每秒重新整理一次日誌檔案到磁碟。當事務提交時,日誌快取不會立刻寫入日誌檔案,這樣的機制不會100%保證每秒都向日誌檔案重新整理日誌,當mysqld程式宕掉的時候可能會丟失持續時間為1秒左右的事務資料。當這個引數為2時,當事務提交後,InnoDB日誌快取中的內容會寫入到日誌檔案且日誌檔案,日誌檔案以大概每秒一次的頻率重新整理到磁碟。在MySQL 5.6.6版本,InnoDB日誌重新整理頻率由innodb_flush_log_at_timeout引數決定。通常將個引數設為1。

innodb_flush_log_at_timeout:寫入或重新整理日誌的時間間隔。這個引數是在MySQL 5.6.6版本引入的。在MySQL 5.6.6版本之前,重新整理的頻率是每秒重新整理一次。innodb_flush_log_at_timeout引數的預設值也是1秒重新整理一次。

innodb_lock_wait_timeout:InnDB事務等待行鎖的時間長度。預設值是50秒。當一個事務鎖定了一行,這時另外一個事務想訪問並修改這一行,當等待時間達到innodb_lock_wait_timeout引數設定的值時,MySQL會報錯"ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction",同時會回滾語句(不是回滾整個事務)。如果想回滾整個事務,需要使用--innodb_rollback_on_timeout引數啟動MySQL。在高互動性的應用系統或OLTP系統上,可以減小這個引數來快速顯示使用者的反饋或把更新放入佇列稍後處理。在資料倉儲中,為了更好的處理執行時間長的操作,可以增大這個引數。這個引數只應用在InnoDB行鎖上,這個引數對錶級鎖無效。這個引數不適用於死鎖,因為發生死鎖時,InnoDB會立刻檢測到死鎖並將發生死鎖的一個事務回退。

innodb_fast_shutdown:InnoDB關庫模式。如果這個引數為0,InnoDB會做一個緩慢關機,在關機前會做完整的重新整理操作,這個級別的關庫操作會持續數分鐘,當快取中的資料量很大時,甚至會持續幾個小時;如果資料庫要執行版本升級或降級,需要執行這個級別的關庫操作,以保證所有的資料變更都寫入到資料檔案。如果這個引數的值是1(預設值),為了節省關庫時間,InnoDB會跳過新操作,而是在下一次開機的時候通過crash recovery方式執行重新整理操作。如果這個引數的值是2,InnoDB會重新整理日誌並以冷方式關庫,就像MySQL當機一樣,沒有提交的事務會丟失,在下一次開啟資料庫時,crash recovery所需要的時間更長;在緊急或排錯情形下,需要立刻關閉資料庫時,會使用這種方式停庫。







About Me

.............................................................................................................................................

● 本文轉載自MySQL官方文件:https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-03-01 09:00 ~ 2017-03-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麥苗出版的資料庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。

   小麥苗的微信公眾號          小麥苗的QQ群             小麥苗的微店

.............................................................................................................................................

MySQL 5.6所有系統變數(系統引數)
DBA筆試面試講解
歡迎與我聯絡



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2135875/,如需轉載,請註明出處,否則將追究法律責任。

相關文章