当前位置:网站首页>System information function of MySQL function summary
System information function of MySQL function summary
2022-07-19 16:39:00 【Operation and maintenance home】
mysql System information function of function summary
mysqlThe system information in has the version number of the database 、 Current user name and number of connections 、 System character set 、 The last one is automatically generatedIDIt's worth waiting for .
obtain mysql Version number 、 Functions of connection number and database name
varsion() Return instructions mysql Server version string .

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29 |
+-----------+
1 row in set (0.00 sec)
mysql>
obtain mysql The number of connections
connection_id() return mysql The number of times the server is currently connected , Each connection has its own unique id;
mysql> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
| 24 |
+-----------------+
1 row in set (0.00 sec)
mysql>
PS: The return value will vary according to the number of login .
obtain mysql Running threads
show processlist: Shows which threads are running , You can not only view the current number of connections , You can also view the current connection status , You can use this to find out the problem sql Statement etc. .
Be careful :
1、 If it is
rootAccount , Can see all users At present Connect . Other users can only see their own .2、
show processlistOnly 100 strip , If you want to see it all, you can useshow full processlistcommand .
mysql> show processlist;
+----+-----------------+-----------------+---------+---------+--------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------------+---------+---------+--------+------------------------+------------------+
| 5 | event_scheduler | localhost | NULL | Daemon | 946721 | Waiting on empty queue | NULL |
| 24 | root | localhost:58414 | test_db | Query | 0 | init | show processlist |
+----+-----------------+-----------------+---------+---------+--------+------------------------+------------------+
2 rows in set (0.01 sec)
mysql>
Use show processlist The meaning of each field of the result found by the command :
ID: The user login mysqlwhen , The system assignscoeenction id;User: Show The current user ; Host: Show which IPOn which port of , It can be used to track the user of the problem statement ;db: Shows which database the process is currently connected to ; Command: Displays the commands executed by the current connection , Generally, the value is sleep ( sleep)、 Inquire about (query)、 Connect (connect);Time: Shows the duration of this state , The unit is seconds ; State: Shows the... Using the current connection sqlThe state of the statement .stateIt's just a state in statement execution . Onesqlsentence , Take the query as an example , May need to go throughcopying to tmp table、sorting result、sending dateWait for the status to complete ;Info: Show this sqlsentence , It is an important basis to judge the problem statement .
View usage utf8 The default database name of the character set
mysql> select database(), schema();
+------------+----------+
| database() | schema() |
+------------+----------+
| test_db | test_db |
+------------+----------+
1 row in set (0.00 sec)
mysql>
Function to get the user name
The following functions can return the current mysql User name and host combination verified by the server :
user() current_user current_user() system_user() session_user()
mysql> select user(), current_user, system_user();
+----------------+----------------+----------------+
| user() | current_user | system_user() |
+----------------+----------------+----------------+
| [email protected] | [email protected] | [email protected] |
+----------------+----------------+----------------+
1 row in set (0.00 sec)
mysql>
The returned result value shows the user name when the current account connects to the server and the connected client host , The rule is : Currently logged in user name @ Currently logged in host .
Get the character set and sorting method of the string
charset(str) Return string str The character set of the argument ;
mysql> select charset('yunweijia') as roll, charset(convert('abc' using latin1)) as roll_1, charset(version()) as roll_2;
+---------+--------+---------+
| roll | roll_1 | roll_2 |
+---------+--------+---------+
| utf8mb3 | latin1 | utf8mb3 |
+---------+--------+---------+
1 row in set (0.00 sec)
mysql>
collation(str) Return string str The character arrangement of ;
mysql> select collation('yunweijia') as coll, collation(convert('yunweijia' using latin1)) as coll_1;
+-----------------+-------------------+
| coll | coll_1 |
+-----------------+-------------------+
| utf8_general_ci | latin1_swedish_ci |
+-----------------+-------------------+
1 row in set (0.00 sec)
mysql>
Get the last automatically generated ID The value of the function
last_insert_id() Function returns the last generated automatically incremented value ;
(1) First we need to create a table ;
mysql> create table test_1 (id int auto_increment not null primary key, name varchar(100));
Query OK, 0 rows affected (0.05 sec)
mysql>
(2) Insert several pieces of data into the table we just created ;
mysql> insert into test_1 values(null, 'zhangsan'), (null, 'lisi'), (null, 'wangwu');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
(3) Check the data in the following table ;
mysql> select * from test_1;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
| 2 | lisi |
| 3 | wangwu |
+----+----------+
3 rows in set (0.00 sec)
mysql>
(4) Use last_insert_id() View the last automatically generated id value ;
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql>
Why would it be 1, instead of 3 Well ?
Keep looking down ;
(5) Insert data again ;
mysql> insert into test_1 values (null, 'yunwei');
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_1 values (null, 'yunweijia');
Query OK, 1 row affected (0.01 sec)
mysql> insert into test_1 values (null, '0909');
Query OK, 1 row affected (0.01 sec)
mysql>
(6) View the contents of the data table
mysql> select * from test_1;
+----+-----------+
| id | name |
+----+-----------+
| 1 | zhangsan |
| 2 | lisi |
| 3 | wangwu |
| 4 | yunwei |
| 5 | yunweijia |
| 6 | 0909 |
+----+-----------+
6 rows in set (0.00 sec)
mysql>
(7) see auto_increment() Value
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 6 |
+------------------+
1 row in set (0.00 sec)
mysql>
Why is that ?
This is because the three pieces of data inserted for the first time , It uses a sql, Use last_insert_id() Use , Only return this one sql Get the first auto_increment Value , That is, although 3 Data , But what he got was only the first piece of data inserted auto_increment Value , That is to say 1;
Why return to 6, Because the three pieces of data inserted later were inserted separately , So what he gets every time belongs to him auto_increment, So I returned 6.
tip :
last_insert_idIt has nothing to do with the data table , If you look at the tabletest_1Insert data into the tabletest_2insert data , thatlast_insert_idGo back to the tabletest_2Mediumauto_incrementValue .
thus , In this paper, the end .
边栏推荐
- JMeter 21 day clock in day09
- Flex layout justify content: the solution of left aligning the last line of space between
- After the media forwarding function is enabled in Vos, calculate the bandwidth occupied by several common codes
- Utiliser l'apprentissage profond pour faire des dessins de cerveau robotique
- Alibaba cloud OSS mapping method
- The unique index exception of the dream database in the Xinchuang environment cannot intercept the duplicatekeyexception
- What is the difference between the then second parameter in promise and catch?
- 【VScode输出为乱码】解决方法
- STM32中断梅开二度(一)
- epoll的ET工作模式和LT工作模式
猜你喜欢

Thesis reading_ Medical NLP_ SMedBERT

Detailed explanation of stop, start and restart commands of Vos services of various versions

Okaleido or get out of the NFT siege, are you optimistic about it?

Weekly resume of personal IP lab · issue 19

Using deep learning to make robot brain drawings

Design and implementation of tcp/ip protocol stack LwIP: Part 4

CSDN認證C1級別學習筆記 - Web進階篇

开发idea插件在提交审核时因为兼容性问题未通过

【Unity3D】UGUI之InputField

VS2019 List Control 控件自绘例程继承CListCtrl类 OnNMCustomdraw重绘
随机推荐
软件设计师:12-案例分析例题
Nacos临时实例和永久实例的区别以及健康检查机制
【Unity3D】UGUI之Dropdown
Latex basic grammar summary
How to buy funds on Alipay? Is it safe
Word文档中封面的下划线如何精确对齐
文件上传通用测试点归纳总结
Is it safe for CITIC Securities to open an account online? What is the process of opening an account?
MATLAB学习第四天(决策语句)
Weekly resume of personal IP lab · issue 19
groovy学习
1805. 字符串中不同整数的数目 ●
用位运算完成大小比较
Design and implementation of tcp/ip protocol stack LwIP: Part 4
揪心!56岁老父亲为了给孩子筹学费,高温工作9小时去世
The NFT market pattern has not changed. Can okaleido set off a new round of waves?
软件设计师:11-基础知识例题
WCF——实现带认证的服务及常见报错
JMeter 21 day clock in day09
dried food! Integrated fair cold start recommendation system