重庆小潘seo博客

当前位置:首页 > 重庆网络营销 > 小潘杂谈 >

小潘杂谈

mysql系统信息函数有哪些?

时间:2020-09-23 06:40:07 作者:重庆seo小潘 来源:
mysql系统信息函数有: 一、查看当前MySQL版本号mysql SELECT VERSION();+-----------+| VERSION() |+-----------+| 5.7.22|+-----------+1 row in set (0.00 sec)二、查看当前用户的连接数mysql SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID

mysql系统信息函数有哪些?

mysql系统信息函数有:

一、查看当前MySQL版本号mysql> SELECT VERSION();+-----------+| VERSION() |+-----------+| 5.7.22|+-----------+1 row in set (0.00 sec)二、查看当前用户的连接数mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+|2 |+-----------------+1 row in set (0.00 sec)三、使用SHOW PROCESSLIST命令输出当前用户的连接信息mysql> SHOW PROCESSLIST;+----+------+------+------+---------+------+----------+------------------+| Id | User | Host | db| Command | Time | State| Info|+----+------+------+------+---------+------+----------+------------------+|2 | root || test | Query|0 | starting | SHOW PROCESSLIST |+----+------+------+------+---------+------+----------+------------------+1 row in set (0.00 sec)四、查看当前使用的数据库mysql> SELECT DATABASE(),SCHEMA();+------------+----------+| DATABASE() | SCHEMA() |+------------+----------+| test| test|+------------+----------+1 row in set (0.00 sec)五、获取当前登录用户名称mysql> SELECT USER(), CURRENT_USER(), SYSTEM_USER();+--------+-----------------------------------+---------------+| USER() | CURRENT_USER()| SYSTEM_USER() |+--------+-----------------------------------+---------------+| root@| skip-grants user@skip-grants host | root@|+--------+-----------------------------------+---------------+1 row in set (0.00 sec)六、 使用CHARSET()函数返回字符串使用的字符集SELECT CHARSET('abc'),CHARSET(CONVERT('abc' USING latin1)),CHARSET(VERSION());+----------------+--------------------------------------+--------------------+| CHARSET('abc') | CHARSET(CONVERT('abc' USING latin1)) | CHARSET(VERSION()) |+----------------+--------------------------------------+--------------------+| utf8| latin1| utf8|+----------------+--------------------------------------+--------------------+1 row in set (0.00 sec)七、使用COLLATION()函数返回字符串排列方式mysql> SELECT COLLATION('abc'),COLLATION(CONVERT('abc' USING utf8));+------------------+--------------------------------------+| COLLATION('abc') | COLLATION(CONVERT('abc' USING utf8)) |+------------------+--------------------------------------+| utf8_general_ci| utf8_general_ci|+------------------+--------------------------------------+1 row in set (0.00 sec)八、使用SELECT LAST_INSERT_ID查看最后一个自动生成的列值

1、一次插入一条记录

(1)、首先创建表worker,其Id字段带有AUTO_INCREMENT约束CREATE TABLE worker (Id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,Name VARCHAR(30));Query OK, 0 rows affected (0.23 sec)(2)、分别单独向表worker中插入2条记录:mysql> INSERT INTO worker VALUES(NULL, 'jimy');Query OK, 1 row affected (0.03 sec)mysql> INSERT INTO worker VALUES(NULL, 'Tom');Query OK, 1 row affected (0.02 sec)mysql> SELECT * FROM worker;+----+------+| Id | Name |+----+------+|1 | jimy ||2 | Tom|+----+------+2 rows in set (0.00 sec)(3)、查看已经插入的数据可以发现,最后一条插入的记录的Id字段值为2,使用LAST_INSERT_ID()查看最后自动生成的Id值:mysql> SELECT LAST_INSERT_ID();+------------------+| LAST_INSERT_ID() |+------------------+|2 |+------------------+1 row in set (0.01 sec)2、一次同时插入多条记录

(1)、接下来,向表中插入多条记录INSERT INTO worker VALUES(NULL, 'Kevin'),(NULL,'Michal'),(NULL,'Nick');Query OK, 3 rows affected (0.03 sec)Records: 3Duplicates: 0Warnings: 0(2)、查询已经插入的的记录,mysql> SELECT * FROM worker;+----+--------+| Id | Name|+----+--------+|1 | jimy||2 | Tom||3 | Kevin||4 | Michal ||5 | Nick|+----+--------+5 rows in set (0.00 sec)mysql> SELECT LAST_INSERT_ID();+------------------+| LAST_INSERT_ID() |+------------------+|3 |+------------------+1 row in set (0.00 sec)以上就是mysql系统信息函数有哪些?的详细内容,更多请关注小潘博客其它相关文章!