系统信息函数是用来查询MySQL数据库的系统信息。

系统信息函数包括查询数据库版本、数据库当前用户等信息。

MySQL系统信息函数如下表所示:

MySQL系统信息函数
version() 返回数据库的版本号
connection_id() 返回服务器的连接数
database() 返回当前数据库名
schema() 返回当前数据库名
user() 返回当前用户名称
system_user() 返回当前用户名称
session_user() 返回当前用户名称
current_user 返回当前用户名称
current_user() 返回当前用户名称
charset(str) 返回字符串str的字符编码
collation(str) 返回字符串str的字符排列方式
last_insert_id() 返回最后生成的auto_increment(自动增长)的值

练习代码:

## MySQL系统信息函数

select version(),connection_id();

select database(),schema();

select user(),system_user(),session_user();

select current_user,current_user();

select charset('admin'),collation('关系型数据库');

select last_insert_id();

运行效果:

MySQL系统信息函数_数据库

MySQL系统信息函数_系统信息_02

MySQL系统信息函数_mysql_03

MySQL系统信息函数_数据库_04

MySQL系统信息函数_系统信息_05

MySQL系统信息函数_系统信息_06