您好,欢迎访问一九零五行业门户网

MySQL学习笔记19:系统信息函数_MySQL

bitscn.com
系统信息函数用来查询mysql数据库的系统信息
 version()返回数据库版本号mysql> select version();+-------------------------+| version() |+-------------------------+| 5.5.28-0ubuntu0.12.10.2 |+-------------------------+1 row in set (0.00 sec)
我这里用的是基于ubuntu发行版,linux mint
connection_id()返回数据库的连接次数mysql> select connection_id();+-----------------+| connection_id() |+-----------------+| 36 |+-----------------+1 row in set (0.00 sec)
其实每次连接到mysql的时候就会有显示
database()、schema()返回当前数据库名mysql> select database(), schema();+------------+----------+| database() | schema() |+------------+----------+| person | person |+------------+----------+1 row in set (0.00 sec)
user()、system_user()、session_user()返回当前用户mysql> select user(), system_user(), session_user();+----------------+----------------+----------------+| user() | system_user() | session_user() |+----------------+----------------+----------------+| root@localhost | root@localhost | root@localhost |+----------------+----------------+----------------+1 row in set (0.00 sec)
current_user()、current_user返回当前用户mysql> select current_user(), current_user;+----------------+----------------+| current_user() | current_user |+----------------+----------------+| root@localhost | root@localhost |+----------------+----------------+1 row in set (0.00 sec)
上面的三个和这两个功能是一样的
charset(str)返回字符串str的字符集mysql> select charset('张三');+-------------------+| charset('张三') |+-------------------+| utf8 |+-------------------+1 row in set (0.00 sec)
collation(str)返回字符串str的字符排列方式mysql> select collation('张三');+---------------------+| collation('张三') |+---------------------+| utf8_general_ci |+---------------------+1 row in set (0.00 sec)
last_insert_id()返回最后生成的auto_increment值mysql> create table t1(id int primary key auto_increment);query ok, 0 rows affected (0.10 sec)mysql> insert into t1 values(null);query ok, 1 row affected (0.04 sec)mysql> insert into t1 values(null);query ok, 1 row affected (0.03 sec)mysql> insert into t1 values(null);query ok, 1 row affected (0.04 sec)mysql> select * from t1;+----+| id |+----+| 1 || 2 || 3 |+----+3 rows in set (0.00 sec)mysql> select last_insert_id();+------------------+| last_insert_id() |+------------------+| 3 |+------------------+1 row in set (0.00 sec)
上面的语句首先创建了一张表t1,其中有一个自增字段id
然后分三次插入null,使其自增
确认已经存在数据之后,使用last_insert_id()获取最后自动生成的值
bitscn.com
其它类似信息

推荐信息