bitsCN.com
系统信息函数用来查询mysql数据库的系统信息
mysql> SELECT VERSION();+-------------------------+| VERSION() |+-------------------------+| 5.5.28-0ubuntu0.12.10.2 |+-------------------------+1 row in set (0.00 sec)
我这里用的是基于ubuntu发行版,Linux Mint
mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+| 36 |+-----------------+1 row in set (0.00 sec)
其实每次连接到mysql的时候就会有显示
mysql> SELECT DATABASE(), SCHEMA();+------------+----------+| DATABASE() | SCHEMA() |+------------+----------+| person | person |+------------+----------+1 row in set (0.00 sec)
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)
mysql> SELECT CURRENT_USER(), CURRENT_USER;+----------------+----------------+| CURRENT_USER() | CURRENT_USER |+----------------+----------------+| root@localhost | root@localhost |+----------------+----------------+1 row in set (0.00 sec)
上面的三个和这两个功能是一样的
mysql> SELECT CHARSET('张三');+-------------------+| CHARSET('张三') |+-------------------+| utf8 |+-------------------+1 row in set (0.00 sec)
mysql> SELECT COLLATION('张三');+---------------------+| COLLATION('张三') |+---------------------+| utf8_general_ci |+---------------------+1 row in set (0.00 sec)
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