Use mysqladminextended-status in Linux with Linux commands to view MySQL running status _ MySQL

Source: Internet
Author: User
This article mainly introduces how to use mysqladminextended-status in Linux with Linux commands to view the running status of MySQL. For more information, see mysqladmin as an important MySQL client, the most common is to use it to shut down the database. In addition, this command can also understand the MySQL running status, process information, and process killing. This article describes how to use mysqladmin extended-status (because there is no "ambiguity", you can use ext instead) to understand the running status of MySQL.

1. use the-r/-I parameter

You can use the mysqladmin extended-status command to obtain all MySQL performance indicators, that is, the output of show global status. However, most of these indicators are accumulative values. if you want to know the current status, A difference calculation is required. this is an additional function of mysqladmin extended-status, which is very practical. By default, extended-status is used, and the result is a cumulative value. However, when the parameter-r (-- relative) is added, the difference between each indicator can be seen, in combination with the parameter-I (-- sleep) you can specify the refresh frequency by using the following command:

The code is as follows:


Mysqladmin-uroot-r-I 1-pxxx extended-status
+ ------------------------------------------ + ---------------------- +
| Variable_name | Value |
+ ------------------------------------------ + ---------------------- +
| Aborted_clients | 0 |
| Com_selected | 336 |
| Com_inserts | 243 |
......
| Threads_created | 0 |
+ ------------------------------------------ + ---------------------- +

2. use with grep

When used with grep, we have:

The code is as follows:


Mysqladmin-uroot-r-I 1-pxxx extended-status \
| Grep "Questions \ | Queries \ | Innodb_rows \ | Com_select \ | Com_insert \ | Com_update \ | Com_delete"
| Com_delete | 1 |
| Com_delete_multi | 0 |
| Com_inserts | 321 |
| Com_selected | 286 |
| Com_update | 63 |
| Innodb_rows_deleted | 1 |
| Innodb_rows_inserted | 207 |
| Innodb_rows_read | 5211 |
| Innodb_rows_updated | 65 |
| Queryies | 2721 |
| Questions | 2721 |

3. use with simple awk

When awk is used, the time information is output simultaneously:

The code is as follows:


Mysqladmin-uroot-p-h127.0.0.1-P3306-r-I 1 ext | \
Awk-F "| "'{\
If ($2 ~ /Variable_name /){\
Print "<-------------" strftime ("% H: % M: % S") "-------------> ";\
}\
If ($2 ~ /Questions | Queries | Innodb_rows | Com_select | Com_insert | Com_update | Com_delete | Innodb_buffer_pool_read_requests /)\
Print $2 $3 ;\
}'
<------------- 12:38:49 ------------->
Com_delete 0
Com_insert 0
Com_select 0
Com_update 0
Innodb_buffer_pool_read_requests 589
Innodb_rows_deleted 0
Innodb_rows_inserted 2
Innodb_rows_read 50
Innodb_rows_updated 50
Queries 105
Questions 1
<------------- 12:38:50 ------------->
Com_delete 0
Com_insert 0
Com_select 0
Com_update 0
Innodb_buffer_pool_read_requests 1814
Innodb_rows_deleted 0
Innodb_rows_inserted 0
Innodb_rows_read 8
Innodb_rows_updated 8
Queries 17
Questions 1

4. combined with a more complex awk

It is not easy, so it is more complicated. This makes the output result more friendly. because awk does not support dynamic variables, the code looks complicated:

The code is as follows:


Mysqladmin-P3306-uroot-p-h127.0.0.1-r-I 1 ext | \
Awk-F "| "\
"BEGIN {count = 0 ;}"\
'{If ($2 ~ /Variable_name/& + + count = 1 ){\
Print "---------- | --------- | --- MySQL Command Status -- | ----- Innodb row operation ---- | -- Buffer Pool Read --";\
Print "--- Time --- | --- QPS --- | select insert update delete | read inserted updated deleted | logical physical ";\
}\
Else if ($2 ~ /Queries/) {queries = $3 ;}\
Else if ($2 ~ /Com_select/) {com_select = $3 ;}\
Else if ($2 ~ /Com_insert/) {com_insert = $3 ;}\
Else if ($2 ~ /Com_update/) {com_update = $3 ;}\
Else if ($2 ~ /Com_delete/) {com_delete = $3 ;}\
Else if ($2 ~ /Innodb_rows_read/) {innodb_rows_read = $3 ;}\
Else if ($2 ~ /Innodb_rows_deleted/) {innodb_rows_deleted = $3 ;}\
Else if ($2 ~ /Innodb_rows_inserted/) {innodb_rows_inserted = $3 ;}\
Else if ($2 ~ /Innodb_rows_updated/) {innodb_rows_updated = $3 ;}\
Else if ($2 ~ /Innodb_buffer_pool_read_requests/) {innodb_lor = $3 ;}\
Else if ($2 ~ /Innodb_buffer_pool_reads/) {innodb_phr = $3 ;}\
Else if ($2 ~ /Uptime/& count> = 2 ){\
Printf ("% s | % 9d", strftime ("% H: % M: % S"), queries );\
Printf ("| % 6d % 6d % 6d % 6d", com_select, com_insert, com_update, com_delete );\
Printf ("| % 6d % 8d % 7d % 7d", innodb_rows_read, innodb_rows_inserted, innodb_rows_updated, innodb_rows_deleted );\
Printf ("| % 10d % 11d \ n", innodb_lor, innodb_phr );\
}}'

The code is as follows:


---------- | --------- | --- MySQL Command Status -- | ----- Innodb row operation ---- | -- Buffer Pool Read --
--- Time --- | --- QPS --- | select insert update delete | read inserted updated deleted | logical physical
10:37:13 | 2231 | 274 214 70 0 | 4811 160 71 0 | 4146 0
10:37:14 | 2972 | 403 256 84 23 | 2509 173 85 23 | 4545 0
10:37:15 | 2334 | 282 232 66 1 | 1266 154 67 1 | 3543 0
10:37:15 | 2241 | 271 217 66 0 | 1160 129 66 0 | 2935 0
10:37:17 | 2497 | 299 224 97 0 | 1141 149 95 0 | 3831 0
10:37:18 | 2871 | 352 304 74 23 | 8202 226 73 23 | 6167 0
10:37:19 | 2441 | 284 233 82 0 | 1099 121 78 0 | 3292 0
10:37:20 | 2342 | 279 242 61 0 | 1083 224 61 0 | 3366 0

In this case, these commands are used a lot and shared with others.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.