0

I need to read this value in a bash script so want to "select" the value but I'm not sure how. Currently I run show global status like 'Com_stmt_pre%'; which returns:

enter image description here

But I need to actually select the value out.

The closest variable I've found is SELECT variable_value FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Prepared_stmt_count'; but the values are different.

2 Answers 2

0

A script method would be:

$ v=$(mysql --skip-column-names -B -e  'show global status like "Com_stmt_prepare"')
$ v="${v##*[:space:]}"
$ echo $v
0

Note: information_schema.GLOBAL_STATUS is not in MySQL-8.0 so show global status needed to be used.

1
  • Unfortunately I get Unknown table GLOBAL_STATUS in information_schema wen running that.
    – webnoob
    Mar 10, 2022 at 6:21
0
  • To get the global status: Select from information_schema.GLOBAL_STATUS
  • To get the global variable: Select from information_schema.GLOBAL_VARIABLES
# Equals `SHOW GLOBAL STATUS LIKE 'com_stmt_pre%';`
SELECT * FROM information_schema.GLOBAL_STATUS 
WHERE variable_name LIKE 'com_stmt_pre%';

Note: It could be different between those if your server is running

2
  • Unfortunately I get Unknown table GLOBAL_STATUS in information_schema when running that.
    – webnoob
    Mar 10, 2022 at 8:46
  • This last line of your answer seems to be incomplete. ...Running what? Mar 11, 2022 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.