MySQL에서 현재 서버에 적용된 구성 변수(시스템 변수)의 목록과 값을 확인하고 싶다면 SHOW 명령어를 사용하면 됩니다. 이 명령어 하나만으로 서버 운영에 관여하는 수백 개의 시스템 변수와 그 설정값을 한눈에 파악할 수 있습니다.
기본 문법: 모든 구성 변수 조회하기
현재 설정된 모든 구성 변수를 표시하는 기본 문법은 다음과 같습니다.
show variables;
LIKE 연산자로 특정 변수만 필터링하기
MySQL의 시스템 변수는 매우 많기 때문에, 실무에서는 LIKE 연산자를 함께 사용해 원하는 변수만 골라서 조회하는 것이 효율적입니다. 기본 문법은 다음과 같습니다.
show variables like '%anyStringValue%';
예제 쿼리
예를 들어, 이름에 'max'가 포함된 구성 변수들을 조회하는 쿼리는 아래와 같습니다.
mysql> show variables like '%max%';
출력 결과
쿼리를 실행하면 다음과 같이 변수 이름(Variable_name)과 현재 값(Value)이 테이블 형태로 출력됩니다.
+------------------------------------------------------+----------------------+ | Variable_name | Value | +------------------------------------------------------+----------------------+ | binlog_max_flush_queue_time | 0 | | cte_max_recursion_depth | 1000 | | ft_max_word_len | 84 | | group_concat_max_len | 1024 | | histogram_generation_max_mem_size | 20000000 | | innodb_adaptive_max_sleep_delay | 150000 | | innodb_change_buffer_max_size | 25 | | innodb_compression_pad_pct_max | 50 | | innodb_ft_max_token_size | 84 | | innodb_io_capacity_max | 2000 | | innodb_max_dirty_pages_pct | 90.000000 | | innodb_max_dirty_pages_pct_lwm | 10.000000 | | innodb_max_purge_lag | 0 | | innodb_max_purge_lag_delay | 0 | | innodb_max_undo_log_size | 1073741824 | | innodb_online_alter_log_max_size | 134217728 | | max_allowed_packet | 4194304 | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | max_connect_errors | 100 | | max_connections | 151 | | max_delayed_threads | 20 | | max_digest_length | 1024 | | max_error_count | 1024 | | max_execution_time | 0 | | max_heap_table_size | 16777216 | | max_insert_delayed_threads | 20 | | max_join_size | 18446744073709551615 | | max_length_for_sort_data | 4096 | | max_points_in_geometry | 65536 | | max_prepared_stmt_count | 16382 | | max_relay_log_size | 0 | | max_seeks_for_key | 4294967295 | | max_sort_length | 1024 | | max_sp_recursion_depth | 0 | | max_user_connections | 0 | | max_write_lock_count | 4294967295 | | myisam_max_sort_file_size | 107374182400 | | mysqlx_max_allowed_packet | 67108864 | | mysqlx_max_connections | 100 | | optimizer_trace_max_mem_size | 1048576 | | parser_max_mem_size | 18446744073709551615 | | performance_schema_max_cond_classes | 80 | | performance_schema_max_cond_instances | -1 | | performance_schema_max_digest_length | 1024 | | performance_schema_max_digest_sample_age | 60 | | 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 | 450 | | performance_schema_max_metadata_locks | -1 | | performance_schema_max_mutex_classes | 300 | | performance_schema_max_mutex_instances | -1 | | performance_schema_max_prepared_statements_instances | -1 | | performance_schema_max_program_instances | -1 | | performance_schema_max_rwlock_classes | 60 | | 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 | 212 | | 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 | 100 | | performance_schema_max_thread_instances | -1 | | range_optimizer_max_mem_size | 8388608 | | slave_max_allowed_packet | 1073741824 | | slave_pending_jobs_size_max | 134217728 | | temptable_max_ram | 1073741824 | +------------------------------------------------------+----------------------+ 74 rows in set (0.01 sec)
위 예제에서는 'max'가 포함된 74개의 변수가 조회되었으며, 실행 시간은 0.01초로 매우 빠릅니다. max_connections(151), max_allowed_packet(4194304)처럼 자주 다루는 핵심 변수들도 이 방식으로 손쉽게 확인할 수 있습니다.
추가로 알아두면 좋은 팁
- 단일 변수 값만 확인:
SELECT @@max_connections;처럼 작성하면 특정 변수 하나의 값만 빠르게 조회할 수 있습니다. - 범위 지정:
SHOW GLOBAL VARIABLES;는 전역(Global) 변수를,SHOW SESSION VARIABLES;는 현재 세션(Session)에 적용된 변수를 조회합니다. - 변수 값 변경:
SET GLOBAL max_connections = 200;과 같이 SET 명령어로 동적으로 변경할 수 있으며, 영구 적용을 위해서는 my.cnf(my.ini) 설정 파일에도 반영해야 합니다. - 변수 출처 확인: MySQL 8.0부터는
performance_schema.variables_info테이블을 조회해 각 변수가 어디서(설정 파일, 명령줄 등) 설정되었는지도 확인할 수 있습니다.