-
MySQL information_schema详解 GLOBAL_VARIABLES和SESSION_VARIABLES
variables
-
-
Attachments
-
Changes
-
View Source
-
View
这个专题主要讲information_ schema数据库下的一些表
如无特殊说明数据库版本为MySQL 5.7.26
## 1. GLOBAL_VARIABLES和SESSION_VARIABLES
这两个表提供和系统变量相关的信息
从 MySQL 5.7.6开始,这两个表开始被废弃,并将在后续的版本移除,信息可以在Performance_schema数据库中查询
这个特性通过show_compatibility_56 参数控制,同时控制系统变量和状态变量
## 2. 迁移系统变量和状态变量
MySQL 5.6的时候如下系统变量和状态变量可以使用show命令获取
```
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_56为ON时代表启用了MySQL 5.6的兼容性,这时和MySQL5.6一直
如果show_compatibility_56为OFF,则代表禁用兼容性,这时表的信息通过peformance_schema获取,这时直接查询information_schame会报错
[image:852 size:orig]
该参数从5.7.8开始默认为OFF
------------------------------
## 3. 实际截图
我们可以直接使用show命令来查询状态变量,系统变量同理,这时不必关心show_compatibility_56参数的值
```
show global variables ;
show session variables ;
```
[image:853 size:orig]
或者使用performance_schema数据库
```
select * from performance_schema.global_status where variable_name ='READ_ONLY';
```
[image:854 size:orig]
## 4. 参考链接
[https://dev.mysql.com/doc/refman/5.7/en/variables-table.html](https://dev.mysql.com/doc/refman/5.7/en/variables-table.html)
[https://dev.mysql.com/doc/refman/5.7/en/performance-schema-variable-table-migration.html](https://dev.mysql.com/doc/refman/5.7/en/performance-schema-variable-table-migration.html)