How to Use mysqladmin to check MySQL running status

Source: Internet
Author: User

How to Use mysqladmin to check MySQL running status

This article describes how to use mysqladmin to check the running status of MySQL, including the simple awk usage of mysqladmin. For more information, see

Mysqladmin is an important MySQL client. It is most commonly used 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:

?

1

2

3

4

5

6

7

8

9

10

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

Mysqladmin-P3306-uroot-p-h127.0.0.1-r-I 1 ext | \

Awk-F "| "\

"BEGIN {count = 0 ;}"\

'{If ($2 ~ /Variable_name/& (++ count) % 20 = 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 );\

}}'

 

---------- | --------- | --- 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 mostly used 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.