mysql_sql查性能语句

Posted linux——quan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql_sql查性能语句相关的知识,希望对你有一定的参考价值。

mysql> SHOW PROCESSLIST;
+----+--------+----------------------+-------+-------------+--------+-----------------------------------------------------------------------+------------------+
| Id | User   | Host                 | db    | Command     | Time   | State                                                                 | Info             |
+----+--------+----------------------+-------+-------------+--------+-----------------------------------------------------------------------+------------------+
|  3 | copy_u | 192.168.31.128:49106 | NULL  | Binlog Dump | 292296 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL             |
|  7 | copy_u | 192.168.31.42:60886  | NULL  | Binlog Dump |   1688 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL             |
|  8 | root   | localhost            | DATA1 | Query       |      0 | init                                                                  | SHOW PROCESSLIST |
+----+--------+----------------------+-------+-------------+--------+-----------------------------------------------------------------------+------------------+
3 rows in set (0.00 sec)
查看系统上运行的所有线程
mysql> SHOW GLOBAL STATUS;
+-----------------------------------------------+-------------+
| Variable_name                                 | Value       |
+-----------------------------------------------+-------------+
| Aborted_clients                               | 2           |
| Aborted_connects                              | 0           |
| Binlog_cache_disk_use                         | 0           |
| Binlog_cache_use                              | 5           |
| Binlog_stmt_cache_disk_use                    | 0           |
| Binlog_stmt_cache_use                         | 4           |
| Bytes_received                                | 8341        |
| Bytes_sent                                    | 57632       |
。。。。。
显示全局变量的所有值

mysql> SHOW SESSION STATUS;
+-----------------------------------------------+-------------+
| Variable_name                                 | Value       |
+-----------------------------------------------+-------------+
| Aborted_clients                               | 2           |
| Aborted_connects                              | 0           |
| Binlog_cache_disk_use                         | 0           |
| Binlog_cache_use                              | 5           |
| Binlog_stmt_cache_disk_use                    | 0           |
| Binlog_stmt_cache_use                         | 4           |
| Bytes_received                                | 601         |
.......
显示会话变量的统计信息

 

mysql> SHOW TABLE STATUS;
+---------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+
| Name    | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation         | Checksum | Create_options | Comment |
+---------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+
| TEST1   | InnoDB |      10 | Compact    |    5 |           3276 |       16384 |               0 |            0 |         0 |           NULL | 2019-10-24 23:54:15 | NULL                | NULL       | latin1_swedish_ci |     NULL |                |         |
| TEST2   | InnoDB |      10 | Compact    |    0 |              0 |       16384 |               0 |            0 |         0 |           NULL | 2019-10-25 14:01:18 | NULL                | NULL       | latin1_swedish_ci |     NULL |                |         |
| emploee | InnoDB |      10 | Compact    |    3 |           5461 |       16384 |               0 |            0 |         0 |           NULL | 2019-10-28 10:41:29 | NULL                | NULL       | latin1_swedish_ci |     NULL |                |         |
| log     | MyISAM |      10 | Dynamic    |    6 |             48 |         292 | 281474976710655 |         2048 |         0 |              7 | 2019-10-28 10:56:35 | 2019-10-28 15:13:51 | NULL       | latin1_swedish_ci |     NULL |                |         |
+---------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+
4 rows in set (0.00 sec)
查看给定数据库的表的详情,包括存储引起,排序规则collation 创建数据,索引数据 行统计信息

mysql> SHOW GLOBAL VARIABLES;
+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name                                          | Value                                                                                                                                                                                                                                                                                                                                            |
+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| auto_increment_increment                               | 1                                                                                                                                                                                                                                                                                                                                                |
| auto_increment_offset                                  | 1                                                                                                                                                                                                                                                                                                                                                |
| autocommit                                             | ON                                                                                                                                                                                                                                                                                                                                               |
| automatic_sp_privileges                                | ON                                                                                                                                                                                                                                                                                                                                               |
| avoid_temporal_upgrade                                 | OFF                                                                                                                                                                                                                                                                                                                                              |
| back_log                                               | 80                                                                                                                                                                                                                                                                                                                                               |
| basedir                                                | /usr/        
。。。。。。
显示系统变量,确定当前配置是否已经被更改或者某些选项是否被设置,有些变量是只读,只能通过配置文件或命令行在启动的时候修改                                                                                                                                                                                                            

 

以上是关于mysql_sql查性能语句的主要内容,如果未能解决你的问题,请参考以下文章

Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段

部分代码片段

012:子查询和增删改查

查看一条mysql语句的性能

Day883.只查一行的语句,也执行这么慢? -MySQL实战

19 | 为什么我只查一行的语句,也执行这么慢?