하루에 MySQL 쿼리를 결정하는 방법은 무엇입니까?


15

MySQL에서 NoSQL DBaaS 로의 큰 전환을 조사 중이며 비용을 예측하는 데 문제가 있습니다. 본질적으로 Cloudant 와 함께 사용할 요청 수를 추정하고 평가하기 위해 현재 MySQL 서버가 하루에 처리하는 쿼리 수를 알 수 없습니다. . 이는 100 PUT, POST 및 DELETE 당 $ 0.015, 500 GET 당 $ 0.015입니다. 그리고 머리.

SHOW STATUSSHOW GLOBAL STATUS 사용에 대한 많은 정보를 찾았습니다 를 MySQL이 자체적으로 수집하는 통계를 얻는 지만 시간대 참조는 없습니다.

예를 들어 SHOW GLOBAL STATUS는 다음을 반환합니다.

Queries                           | 13576675

그 숫자를 감싸는 기간을 모른다는 것을 제외하고는 어느 것이 좋습니다. 언제 13 백만 쿼리? 달마다? 년? 시간의 시작부터?

MySQL 문서는 실제로 너무 정교하지 않습니다.

쿼리

서버가 실행 한 명령문 수 이 변수에는 질문 변수와 달리 저장된 프로그램 내에서 실행 된 명령문이 포함됩니다. COM_PING 또는 COM_STATISTICS 명령은 계산하지 않습니다. 이 변수는 MySQL 5.0.76에서 추가되었습니다.

도움을 주셔서 감사합니다.


2
Queries글로벌 상태 변수였다 서버가 마지막으로 시작된 이후 모든 ... 세고 SHOW STATUS LIKE 'Uptime';초 전. 많은 상태 변수가 지워 FLUSH STATUS;졌지만 Queries적어도 지금 테스트 한 서버에서는 MySQL 5.5.19 및 5.6.14였습니다.
Michael-sqlbot

답변:


15

SELECT의 경우 :

show global status like "Com_select";

업데이트 :

show global status like "Com_update";

삽입 :

show global status like "Com_insert";

삭제 :

show global status like "Com_delete";

MySQL 마지막 재시작 이후 ALl 값은 "cumulativ"입니다.

한 시간 내에 SELECT를 얻으려면 다음을 수행하십시오.

오후 9시 :

[21:00:00] [DEV\(none)] mysql> show global status like "Com_select";
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| Com_select    | 671664 |
+---------------+--------+
1 row in set (0.00 sec)

오후 10시 :

[22:00:00] [DEV\(none)] mysql> show global status like "Com_select";
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| Com_select    | 672363 |
+---------------+--------+
1 row in set (0.00 sec)

지난 1 시간 동안의 SELECT 수 : 672363-671664 = 699

친애하는


감사합니다 @mfouilleul, 이것은 도움이됩니다. 이것을 기간 var와 결합하고 쿼리의 양을 알아낼 것입니다.
AJB

1
명확히하기 위해 show global status like 'Com_%';명령은 전체 서버에 대한 것입니다. 공유 환경에서 대안이 될 수있는 것-예 : max_questions최대 시간당 쿼리 수 (QPH) 에서 얼마나 멀리 떨어져 있는지 추정하기 위해 .
Fabien Snauwaert

9

이 뷰를 사용하여 초당, 분, 시간 및 일당 쿼리 수를 감시합니다.

create or replace view _dba_query_stats as
select 
  SUBSTRING(VARIABLE_NAME, 5) as query_type, 
  VARIABLE_VALUE as total_count, 
  round(VARIABLE_VALUE / ( select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'), 2) as per_second,
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60)))       as per_minute,
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60)))    as per_hour, 
  round(VARIABLE_VALUE / ((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status') / (60*60*24))) as per_day,
  FROM_UNIXTIME(round(UNIX_TIMESTAMP(sysdate()) - (select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status'))) report_period_start,
  sysdate() as report_period_end,
  TIME_FORMAT(SEC_TO_TIME((select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Uptime_since_flush_status')),'%Hh %im') as report_period_duration
from 
  information_schema.GLOBAL_STATUS 
where 
  VARIABLE_NAME in ('Com_select', 'Com_delete', 'Com_update', 'Com_insert');

샘플 출력 :

query_type total_count per_second per_minute per_hour per_day report_period_start report_period_end   report_period_duration
DELETE               0          0          0       0        0 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
INSERT           36595       0.09          5     320     7672 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
SELECT        14842019      36.02       2161  129656  3111738 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
UPDATE          189137       0.46         28    1652    39654 2017-04-16 03:46    2017-04-20 22:14:56 114h 28m
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.