如何显示MySQL服务器的系统变量?

王林
王林 转载
2023-09-23 16:13:07 425浏览

如何显示MySQL服务器的系统变量?

使用 SHOW VARIABLES 显示 MySQL 系统变量值。此语句不需要任何特权。只需要能够连接到服务器即可。

语法

SHOW [GLOBAL | SESSION] VARIABLES
   [LIKE 'pattern' | WHERE expr]

LIKE 子句(如果存在)告诉 SHOW VARIABLES 要匹配哪些变量名称。要根据更广泛的条件选择行,请使用 WHERE 子句。

SHOW VARIABLES 接受可选的全局或会话变量范围修改 -

  • 当 GLOBAL 用作修​​饰符时,该语句显示全局系统变量的值。对于 MySQL 的新连接,这些是用于初始化关联会话变量的值。如果变量没有全局值,则不会显示该变量的值。

  • 该语句显示使用 SESSION 修饰符时对当前连接有效的系统变量值。如果变量没有会话值,则会显示该变量的全局值。 SESSION 是 LOCAL 的另一种说法。

  • 如果未指定修饰符,则默认为 SESSION。

SHOW VARIABLES 存在与版本相关的显示宽度限制。使用 SELECT 作为具有未完全显示的极长值的变量的解决方法。例如 -

SELECT @@GLOBAL.innodb_data_file_path;

虽然像 version_comment 这样的只读变量是一个例外,但大多数系统变量都可以在服务器启动时配置。使用 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.2,TLSv1.3              |
| 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 子句(如图所示)获取特定变量的行 -

% 是通配符,可在 LIKE 子句中使用,以获取名称与模式匹配的变量列表:

SHOW VARIABLES LIKE '%auto%';
SHOW GLOBAL VARIABLES LIKE '%auto%';

输出

+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_attach              | ON    |
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
| auto_replicate           | OFF   |
| autocommit               | ON    |
+--------------------------+-------+
SHOW GLOBAL VARIABLES LIKE 'version%';

输出

+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| version                 | 5.1.16-beta                  | 
| version_comment         | MySQL Community Server (GPL) | 
| version_compile_machine | i686                         | 
| version_compile_os      | pc-linux-gnu                 | 
+-------------------------+------------------------------+

要匹配的模式在任何位置接受通配符。要从字面上匹配它,您应该转义,因为它是匹配任何字符的通配符。实际上,很少需要这样做。

使用这些命令,您可以使用 MySQL 显示其所有系统变量。如前所述,使用它们不需要任何特权;所需要的只是与数据库服务器的连接。

以上就是如何显示MySQL服务器的系统变量?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除