SHOW VARIABLES语句
SHOW [GLOBAL |SESSION ]VARIABLES [LIKE 'pattern' |WHERE expr]
SHOW VARIABLES
显示MySQL系统变量的值(请参见“服务器系统变量”)。该语句不需要任何特权。它仅需要连接到服务器的能力。
也可以从以下来源获得系统变量信息:
- 性能架构表。请参见“性能架构系统变量表”。
- 在中mysqladmin变量命令。请参见“mysqladmin-用于管理MySQL服务器的客户端”。
对于SHOW VARIABLES
,LIKE
子句(如果存在)指示要匹配的变量名称。如“ SHOW语句的扩展”WHERE
所述,可以提供一个子句来使用更通用的条件选择行。
SHOW VARIABLES
接受可选GLOBAL
或SESSION
可变范围修饰符:
- 使用
GLOBAL
修饰符,该语句显示全局系统变量值。这些是用于初始化与MySQL的新连接的相应会话变量的值。如果变量没有全局值,则不会显示任何值。 - 使用
SESSION
修饰符,该语句显示对当前连接有效的系统变量值。如果变量没有会话值,则显示全局值。LOCAL
是的同义词SESSION
。 - 如果不存在修饰符,则默认值为
SESSION
。
“服务器系统变量”中列出了每个系统变量的范围。
SHOW VARIABLES
受版本依赖的显示宽度限制。对于没有完全显示的具有非常长的值的变量,请使用SELECT
变通办法。例如:
SELECT @@GLOBAL.innodb_data_file_path;
可以在服务器启动时设置大多数系统变量(只读变量,例如,version_comment
例外)。许多可以在运行时使用该SET
语句进行更改。请参见“使用MySQL服务器系统变量”和“变量分配的SET语法”。
部分输出显示在这里。服务器的名称和值列表可能有所不同。“服务器系统变量”描述了每个变量的含义,“配置服务器”提供了有关调整它们的信息。
mysql>SHOW VARIABLES ; +-------------------------------------------- +------------------------------ + | Variable_name | Value | +-------------------------------------------- +------------------------------ + | activate_all_roles_on_login | OFF | | auto_generate_certs | ON | | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | avoid_temporal_upgrade | OFF | | back_log | 151 | | 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_expire_logs_seconds | 2592000 | | 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_row_metadata | MINIMAL | | binlog_row_value_options | | | 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 | ... | max_allowed_packet | 67108864 | | 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 | ... | thread_handling | one -thread -per -connection | | thread_stack | 286720 | | time_zone | SYSTEM | | timestamp | 1530906638.765316 | | 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 | XXHASH64 | | unique_checks | ON | | updatable_views_with_limit | YES | | version | 8.0.12 | | version_comment | MySQL Community Server - GPL | | version_compile_machine | x86_64 | | version_compile_os | Linux | | version_compile_zlib | 1.2.11 | | wait_timeout | 28800 | | warning_count | 0 | | windowing_use_high_precision | ON | +-------------------------------------------- +------------------------------ +
使用LIKE
子句,该语句仅显示名称与模式匹配的那些变量的行。要获取特定变量的行,请使用LIKE
如下所示的子句:
SHOW VARIABLES LIKE 'max_join_size';SHOW SESSION VARIABLES LIKE 'max_join_size';
要获取名称与模式匹配的变量列表,请%
在LIKE
子句中使用通配符:
SHOW VARIABLES LIKE '%size%';SHOW GLOBAL VARIABLES LIKE '%size%';
通配符可以在要匹配的模式中的任何位置使用。严格来说,因为_
是一个与任何单个字符匹配的通配符,所以您应该对其进行转义\_
以使其在字面上匹配。实际上,这几乎没有必要。