MySQL study Note 19: System information function bitsCN.com
The system information function is used to query the system information of the mysql database.
VERSION () returns the database VERSION number.
mysql> SELECT VERSION();+-------------------------+| VERSION() |+-------------------------+| 5.5.28-0ubuntu0.12.10.2 |+-------------------------+1 row in set (0.00 sec)
I am using the ubuntu-based release, Linux Mint
CONNECTION_ID () returns the number of database connections
mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+| 36 |+-----------------+1 row in set (0.00 sec)
In fact, each connection to mysql will display
DATABASE (), SCHEMA () returns the current DATABASE name
mysql> SELECT DATABASE(), SCHEMA();+------------+----------+| DATABASE() | SCHEMA() |+------------+----------+| person | person |+------------+----------+1 row in set (0.00 sec)
USER (), SYSTEM_USER (), SESSION_USER () returns the current 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 returns the current user
mysql> SELECT CURRENT_USER(), CURRENT_USER;+----------------+----------------+| CURRENT_USER() | CURRENT_USER |+----------------+----------------+| root@localhost | root@localhost |+----------------+----------------+1 row in set (0.00 sec)
The above three functions are the same as the two functions.
CHARSET (str) returns the character set of the str string
Mysql> select charset ('Zhang San'); + ----------------- + | CHARSET ('Zhang San') | + --------------------- + | utf8 | + ------------------- + 1 row in set (0.00 sec)
COLLATION (str) returns the character arrangement of the str string.
Mysql> select collation ('Zhang San'); + ------------------- + | COLLATION ('Zhang San') | + signature + | utf8_general_ci | + --------------------- + 1 row in set (0.00 sec)
LAST_INSERT_ID () returns the final AUTO_INCREMENT value.
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)
The preceding statement first creates a table t1 with an auto-increment Field id.
Insert NULL three times to enable auto-increment.
After confirming that the data already exists, use LAST_INSERT_ID () to obtain the last automatically generated value.
BitsCN.com