详细解决The INFORMATION_SCHEMA.xxx feature is disabled; see the documentation for show_compatibility_56

小咪咪 2024-02-21 10:37 121阅读 0赞

文章目录

    1. 复现错误
    1. 分析错误
    1. 解决问题

1. 复现错误

今天,在使用MySQL查询全局变量时,却报出如下错误:

  1. mysql> select * from information_schema.global_variables;
  2. ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.GLOBAL_VARIABLES' feature is disabled; see the documentation for 'show_compatibility_56'

The 'INFORMATION_SCHEMA.GLOBAL_VARIABLES' feature is disabled; see the documentation for 'show_compatibility_56'

同时,使用MySQL查询全局状态时,报出如下同样的错误:

  1. mysql> select * from information_schema.global_status;
  2. ERROR 3167 (HY000): The 'INFORMATION_SCHEMA.GLOBAL_STATUS' feature is disabled; see the documentation for 'show_compatibility_56'

The 'INFORMATION_SCHEMA.GLOBAL_STATUS' feature is disabled; see the documentation for 'show_compatibility_56'

2. 分析错误

The 'INFORMATION_SCHEMA.GLOBAL_VARIABLES' feature is disabled; see the documentation for 'show_compatibility_56'翻译成中文,便是'INFORMATION_SCHEMA.GLOBAL_VARIABLES“功能已禁用,请参阅“show_compatibility_56”的文档

同样,INFORMATION_SCHEMA.GLOBAL_STATUS功能也已禁用。

INFORMATION_SCHEMA.GLOBAL_VARIABLESINFORMATION_SCHEMA.GLOBAL_STATUS,这两个表为什么会被禁用,还要从MySQL的版本说起。

这两个表提供和系统变量相关的信息。

MySQL 5.7.6开始,这两个表开始被废弃,并将在后续的版本移除,使用如下sql查询我的MySQL版本:

  1. mysql> select version();
  2. ```dart
  3. +------------+
  4. | version() |
  5. +------------+
  6. | 5.7.16-log |
  7. +------------+
  8. 1 row in set (0.00 sec)

这个特性通过show_compatibility_56参数控制,同时控制系统变量和状态变量,该参数从5.7.8开始默认为OFF

  1. 我的`MySQL`版本是`5.7.16`,因而,`INFORMATION_SCHEMA.GLOBAL_VARIABLES``INFORMATION_SCHEMA.GLOBAL_STATUS` 被禁用(废弃),但信息可以在`Performance_schema`数据库中查询:
  2. - `performance_schema.global_variables`
  3. ```sql
  4. mysql> select * from performance_schema.global_variables;
  5. +--------------------------+----------------+
  6. | VARIABLE_NAME | VARIABLE_VALUE |
  7. +--------------------------+----------------+
  8. | auto_increment_increment | 1 |
  9. | auto_increment_offset | 1 |
  10. | autocommit | ON |
  11. | automatic_sp_privileges | ON |
  12. | avoid_temporal_upgrade | OFF |
  13. | ...... | ...... |
  14. +--------------------------+----------------+
  15. 491 rows in set (0.00 sec)
  • performance_schema.global_status

    mysql> select * from performance_schema.global_status;
    +——————————————+————————+
    | VARIABLE_NAME | VARIABLE_VALUE |
    +——————————————+————————+
    | Aborted_clients | 8 |
    | Aborted_connects | 1 |
    | Binlog_cache_disk_use | 0 |
    | Binlog_cache_use | 0 |
    | Binlog_stmt_cache_disk_use | 0 |
    | …… | …… |
    +——————————————+————————+
    206 rows in set (0.00 sec)

当然,MySQL 5.6之后的系统变量和状态变量,除了使用performance_schema,也可以使用show命令获取:

  • SHOW VARIABLES,如下图所示:

在这里插入图片描述

  • SHOW STATUS,如下图所示:

在这里插入图片描述

SHOW VARIABLESSHOW STATUS的数据来源于如下表

  1. INFORMATION_SCHEMA.GLOBAL_VARIABLES
  2. INFORMATION_SCHEMA.SESSION_VARIABLES
  3. INFORMATION_SCHEMA.GLOBAL_STATUS
  4. INFORMATION_SCHEMA.SESSION_STATUS

MySQL 5.7.6开始后改成了从如下表获取:

  1. performance_schema.global_variables
  2. performance_schema.session_variables
  3. performance_schema.variables_by_thread
  4. performance_schema.global_status
  5. performance_schema.session_status
  6. performance_schema.status_by_thread
  7. performance_schema.status_by_account
  8. performance_schema.status_by_host
  9. performance_schema.status_by_user

从该版本开始MySQL引入了show_compatibility_56参数,来控制show命令从什么地方获取值。

show_compatibility_56ON时代表启用了MySQL 5.6的兼容性,这时和MySQL5.6一直

如果show_compatibility_56OFF,则代表禁用兼容性,这时表的信息通过peformance_schema获取,这时直接查询information_schame会报出如上的错误。

使用如下代码,查看show_compatibility_56,是否关闭:

  1. mysql> show variables like '%show_compatibility_56%';
  2. +-----------------------+-------+
  3. | Variable_name | Value |
  4. +-----------------------+-------+
  5. | show_compatibility_56 | OFF |
  6. +-----------------------+-------+
  7. 1 row in set, 1 warning (0.00 sec)

3. 解决问题

可以使用如下方法解决该问题:

  1. 使用performance_schema.global_variablesperformance_schema.global_status查询系统变量,如上代码所示。

    mysql> select * from performance_schema.global_variables where variable_name like ‘%timeout%’;
    +——————————————-+————————+
    | VARIABLE_NAME | VARIABLE_VALUE |
    +——————————————-+————————+
    | connect_timeout | 10 |
    | delayed_insert_timeout | 300 |
    | have_statement_timeout | YES |
    | innodb_flush_log_at_timeout | 1 |
    | innodb_lock_wait_timeout | 50 |
    | innodb_rollback_on_timeout | OFF |
    | interactive_timeout | 28800 |
    | lock_wait_timeout | 31536000 |
    | net_read_timeout | 30 |
    | net_write_timeout | 60 |
    | rpl_stop_slave_timeout | 31536000 |
    | slave_net_timeout | 60 |
    | wait_timeout | 28800 |
    +——————————————-+————————+
    13 rows in set, 1 warning (0.00 sec)

  2. 使用show variablesshow status查询系统变量

    mysql> show variables like ‘%%timeout’;
    +——————————————-+—————+
    | Variable_name | Value |
    +——————————————-+—————+
    | connect_timeout | 10 |
    | delayed_insert_timeout | 300 |
    | have_statement_timeout | YES |
    | innodb_flush_log_at_timeout | 1 |
    | innodb_lock_wait_timeout | 50 |
    | innodb_rollback_on_timeout | OFF |
    | interactive_timeout | 28800 |
    | lock_wait_timeout | 31536000 |
    | net_read_timeout | 30 |
    | net_write_timeout | 60 |
    | rpl_stop_slave_timeout | 31536000 |
    | slave_net_timeout | 60 |
    | wait_timeout | 28800 |
    +——————————————-+—————+
    13 rows in set, 1 warning (0.00 sec)

  3. show_compatibility_56设置为on,兼容之前的版本:

    mysql> set global show_compatibility_56 = ON;
    Query OK, 0 rows affected (0.00 sec)

查询是否设置成功:

  1. mysql> show variables like '%show_compatibility_56%';
  2. +-----------------------+-------+
  3. | Variable_name | Value |
  4. +-----------------------+-------+
  5. | show_compatibility_56 | ON |
  6. +-----------------------+-------+
  7. 1 row in set (0.00 sec)

如下,便可以在information_schema.global_variables表中查询数据了:

  1. mysql> select * from information_schema.global_variables where variable_name like '%timeout%' ;
  2. +-----------------------------+----------------+
  3. | VARIABLE_NAME | VARIABLE_VALUE |
  4. +-----------------------------+----------------+
  5. | INNODB_FLUSH_LOG_AT_TIMEOUT | 1 |
  6. | RPL_STOP_SLAVE_TIMEOUT | 31536000 |
  7. | INNODB_ROLLBACK_ON_TIMEOUT | OFF |
  8. | DELAYED_INSERT_TIMEOUT | 300 |
  9. | CONNECT_TIMEOUT | 10 |
  10. | SLAVE_NET_TIMEOUT | 60 |
  11. | NET_WRITE_TIMEOUT | 60 |
  12. | INNODB_LOCK_WAIT_TIMEOUT | 50 |
  13. | LOCK_WAIT_TIMEOUT | 31536000 |
  14. | HAVE_STATEMENT_TIMEOUT | YES |
  15. | NET_READ_TIMEOUT | 30 |
  16. | INTERACTIVE_TIMEOUT | 28800 |
  17. | WAIT_TIMEOUT | 28800 |
  18. +-----------------------------+----------------+
  19. 13 rows in set, 1 warning (0.00 sec)

发表评论

表情:
评论列表 (有 0 条评论,121人围观)

还没有评论,来说两句吧...

相关阅读