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

1. 复现错误


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

mysql> select * from information_schema.global_variables;

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查询全局状态时,报出如下同样的错误:

mysql> select * from information_schema.global_status;

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版本:

mysql> select version();

```dart
+------------+
| version()  |
+------------+
| 5.7.16-log |
+------------+
1 row in set (0.00 sec)

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


我的`MySQL`版本是`5.7.16`,因而,`INFORMATION_SCHEMA.GLOBAL_VARIABLES`和`INFORMATION_SCHEMA.GLOBAL_STATUS` 被禁用(废弃),但信息可以在`Performance_schema`数据库中查询:

-  `performance_schema.global_variables`

```sql
mysql> select * from performance_schema.global_variables;
+--------------------------+----------------+
| VARIABLE_NAME            | VARIABLE_VALUE |
+--------------------------+----------------+
| auto_increment_increment | 1              |
| auto_increment_offset    | 1              |
| autocommit               | ON             |
| automatic_sp_privileges  | ON             |
| avoid_temporal_upgrade   | OFF            |
| ......                   | ......         |
+--------------------------+----------------+

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 VARIABLES SHOW STATUS的数据来源于如下表

INFORMATION_SCHEMA.GLOBAL_VARIABLES
INFORMATION_SCHEMA.SESSION_VARIABLES 
INFORMATION_SCHEMA.GLOBAL_STATUS 
INFORMATION_SCHEMA.SESSION_STATUS

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

performance_schema.global_variables 
performance_schema.session_variables 
performance_schema.variables_by_thread 
performance_schema.global_status 
performance_schema.session_status 
performance_schema.status_by_thread 
performance_schema.status_by_account 
performance_schema.status_by_host 
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,是否关闭:

mysql> show variables like '%show_compatibility_56%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| show_compatibility_56 | OFF   |
+-----------------------+-------+
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)
  1. 使用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)
  1. show_compatibility_56设置为on,兼容之前的版本:
mysql> set global show_compatibility_56 = ON;
Query OK, 0 rows affected (0.00 sec)

查询是否设置成功:

mysql> show variables like '%show_compatibility_56%';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| show_compatibility_56 | ON    |
+-----------------------+-------+
1 row in set (0.00 sec)

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

mysql> select * from information_schema.global_variables where variable_name like '%timeout%' ;
+-----------------------------+----------------+
| VARIABLE_NAME               | VARIABLE_VALUE |
+-----------------------------+----------------+
| INNODB_FLUSH_LOG_AT_TIMEOUT | 1              |
| RPL_STOP_SLAVE_TIMEOUT      | 31536000       |
| INNODB_ROLLBACK_ON_TIMEOUT  | OFF            |
| DELAYED_INSERT_TIMEOUT      | 300            |
| CONNECT_TIMEOUT             | 10             |
| SLAVE_NET_TIMEOUT           | 60             |
| NET_WRITE_TIMEOUT           | 60             |
| INNODB_LOCK_WAIT_TIMEOUT    | 50             |
| LOCK_WAIT_TIMEOUT           | 31536000       |
| HAVE_STATEMENT_TIMEOUT      | YES            |
| NET_READ_TIMEOUT            | 30             |
| INTERACTIVE_TIMEOUT         | 28800          |
| WAIT_TIMEOUT                | 28800          |
+-----------------------------+----------------+
13 rows in set, 1 warning (0.00 sec)

猜你喜欢

转载自blog.csdn.net/lvoelife/article/details/133974370
今日推荐