mysql信息函数

mysql> SELECT CONNECTION_ID();  #当前连接的ID
+-----------------+
| CONNECTION_ID() |
+-----------------+
| 1 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT DATABASE();   #当前打开的数据库
+------------+
| DATABASE() |
+------------+
| test |
+------------+

mysql> SHOW COLUMNS FROM test;   #
+----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+----------------+
| id | tinyint(3) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | YES | | NULL | |
+----------+---------------------+------+-----+---------+----------------+

mysql> INSERT test VALUES(NULL,'Mary'), (NULL, 'H');
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM test;
+----+----------+
| id | username |
+----+----------+
| 1 | John |
| 2 | Mary |
| 3 | 1%Lily |
| 4 | Rose |
| 5 | NULL |
| 6 | Mary |
| 7 | Mary |
| 8 | H |
+----+----------+
8 rows in set (0.00 sec)

mysql> SELECT LAST_INSERT_ID();  #最后插入记录的ID号(数据表中必须存在自动编号的字段,字段名不一定为id)
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 7 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT USER();  #打印当前登录的用户
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.01 sec)

mysql> SELECT VERSION();  #打印mysql版本的信息
+-----------+
| VERSION() |
+-----------+
| 5.5.54 |
+-----------+

原文地址:https://www.cnblogs.com/toudoubao/p/6636224.html