{"id":527,"date":"2019-02-27T01:54:41","date_gmt":"2019-02-27T01:54:41","guid":{"rendered":"https:\/\/monyog.jp\/?p=527"},"modified":"2019-03-07T02:22:23","modified_gmt":"2019-03-07T02:22:23","slug":"mysql%e5%a4%89%e6%95%b0%e3%81%a8%e3%82%b7%e3%82%b9%e3%83%86%e3%83%a0%e3%83%87%e3%83%bc%e3%82%bf","status":"publish","type":"post","link":"https:\/\/smart-style.main.jp\/monyogjp\/static\/document\/527\/index.html","title":{"rendered":"MySQL\u5909\u6570\u3068\u30b7\u30b9\u30c6\u30e0\u30c7\u30fc\u30bf"},"content":{"rendered":"

mysql.data\u3068system.data<\/h2>\n

\u3053\u306e2\u3064\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u69cb\u9020\u306f\u3001\u307e\u3063\u305f\u304f\u540c\u3058\u3067\u3059\uff1a<\/p>\n

\r\nCREATE TABLE IF NOT EXISTS [metric_master] (\r\n   [metric_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\r\n   [metric_desc] TEXT ASC UNIQUE )\r\n<\/pre>\n
\r\nCREATE TABLE IF NOT EXISTS [snapshot_master] (\r\n   [timestamp_id] INTEGER NOT NULL,\r\n   [metric_id] INTEGER NOT NULL,\r\n   [metric_now] TEXT,\r\n   [metric_diff] TEXT,\r\n   PRIMARY KEY (metric_id, timestamp_id))<\/pre>\n
CREATE INDEX IF NOT EXISTS [timestamp_id_index] ON [snapshot_master] ([timestamp_id])<\/pre>\n
CREATE TABLE IF NOT EXISTS [timestamp_master] (\r\n   [timestamp_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\r\n   [server_timestamp] INTEGER,\r\n   [server_start_time] INTEGER,\r\n   [server_uptime] INTEGER,\r\n   [server_uptime_diff] INTEGER,\r\n   [server_is_connected] INTEGER)\r\n<\/pre>\n
  CREATE INDEX IF NOT EXISTS [server_timestamp_idx] ON [timestamp_master] ([server_timestamp])\r\n<\/pre>\n

\u3053\u308c\u304b\u3089\u306e\u8aac\u660e\u3092\u7406\u89e3\u3059\u308b\u4e0a\u3067\u3001\u6700\u3082\u5927\u4e8b\u306a\u306e\u306f\u3001[snapshot_master]\u30c6\u30fc\u30d6\u30eb\u3068[timestamp_master]\u30c6\u30fc\u30d6\u30eb\u306e\u4e21\u65b9\u306b\u3042\u308b[timestamp_id]\u5217\u3067\u3059\u3002\u305d\u3053\u3067\u3001MySQL\u3068InnoDB\u3067\u306f\u3001\u6574\u5408\u6027\u3068\u660e\u77ad\u6027\u3092\u78ba\u4fdd\u3059\u308b\u305f\u3081\u306b\u3001[snapshot_master]\u304b\u3089[timestamp_master]\u3068\u3092\u95a2\u9023\u4ed8\u3051\u308b\u5916\u90e8\u30ad\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u3053\u306e2\u3064\u3092\u30af\u30a8\u30ea\u3067JOIN\u3059\u308b\u304b\u3001SUBQUERY\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n

\u4ee5\u4e0a\u306e\u57fa\u672c\u7684\u6a5f\u80fd\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\uff1a<\/p>\n

    \n
  • SQL Diagnostic Manager\u304c\u3042\u308b\u7a2e\uff08Linux\/proc\u30d5\u30a9\u30eb\u30c0\u30fc\u304b\u3089OS\u30e1\u30c8\u30ea\u30c3\u30af\u3092\u53d6\u5f97\uff09\u306eSHOW VARIABLES\/STATUS\u306e\u3088\u3046\u306a\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u9001\u4fe1\u3059\u308b\u305f\u3073\u306b\u3001\u73fe\u5728\u306e\u6642\u523b\u306b\u95a2\u3059\u308b\u60c5\u5831\u3068\u3068\u3082\u306b\u30011\u884c\u304c\u201ctimestamp_master\u201d\u30c6\u30fc\u30d6\u30eb\u306bINSERTED\u3055\u308c\u3001\u305d\u306e\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3067\u53d6\u308a\u51fa\u3055\u308c\u305f\u30e1\u30c8\u30ea\u30c3\u30af\u304c[snapshot_master]\u306bINSERTED\u3055\u308c\u307e\u3059\u3002\u201csnapshot_master\u201d\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u3001\u30e1\u30c8\u30ea\u30c3\u30af\u306e\u8a73\u7d30\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u307e\u3059\u3002[timestamp_id]\u5217\u306f\u3001\u30e1\u30c8\u30ea\u30c3\u30af\u306e\u305d\u306e\u6642\u70b9\u306e\u72b6\u614b\u3092\u8b58\u5225\u3057\u307e\u3059\u3002\u307e\u305f\u3001SQL Diagnostic Manager\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u306f\u3001unix_timestamps\u3067\u3059\u3002<\/li>\n
  • \u5b9f\u969b\u306b\u306f\u3001\u5fc5\u305a\u3057\u3082\u3044\u3064\u3082[snapshot_master]\u306bINSERT\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u4f55\u304b\u304c\u305d\u306e\u30e1\u30c8\u30ea\u30c3\u30af\u306bINSERTED\u3055\u308c\u305f\u5f8c\u306b\u3001\u7279\u5b9a\u306e\u30e1\u30c8\u30ea\u30c3\u30af\u304c\u5909\u66f4\u3055\u308c\u305f\u5834\u5408\u306e\u307f\u3001\u518d\u3073INSERT\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u3069\u3053\u304b\u7279\u5b9a\u306e\u6642\u70b9\u306e\u30e1\u30c8\u30ea\u30c3\u30af\u306e\u5024\u3092\u77e5\u308a\u305f\u3044\u3068\u304d\u306f\u3001\u305d\u306e\u7279\u5b9a\u306e\u30e1\u30c8\u30ea\u30c3\u30af\u306e\u7279\u5b9a\u306e\u6642\u523b\u3088\u308a\u524d\u306b\u4fdd\u5b58\u3055\u308c\u305f\u6700\u65b0\u306e\u5024\u3092\u63a2\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n
  • \u6700\u5f8c\u306b\u3001[snapshot_master]\u306b\u306f\u3001\u30e1\u30c8\u30ea\u30c3\u30af\u540d\u304c\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3042\u3089\u304b\u3058\u3081\u30b5\u30fc\u30d0\u30fc\u304c\u3069\u306e\u30e1\u30c8\u30ea\u30c3\u30af\u3092\u8fd4\u3059\u304b\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u306e\u8a73\u7d30\u60c5\u5831\uff08\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u69cb\u6210\uff09\u306b\u3088\u3063\u3066\u7570\u306a\u308b\u305f\u3081\u3001\u305d\u308c\u3092\u4e88\u6e2c\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u307e\u305f\u3001\u30b5\u30fc\u30d0\u30fc\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u3055\u3089\u306b\u3001\u30c7\u30a3\u30b9\u30af \u30b9\u30da\u30fc\u30b9\u3092\u7bc0\u7d04\u3059\u308b\u305f\u3081\u3001\u30c6\u30ad\u30b9\u30c8\u8aac\u660e\u304c\u4fdd\u5b58\u3055\u308c\u308b\u306e\u306f1\u56de\u3060\u3051\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001[snapshot_master]\u306b\u3042\u308b\u306e\u306f\u3001[metric_master]\u30c6\u30fc\u30d6\u30eb\u306e\u30c6\u30ad\u30b9\u30c8\u8aac\u660e\u3092\u53c2\u7167\u3059\u308b[metric_id]\u5217\u306e\u756a\u53f7\u3060\u3051\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30af\u30a8\u30ea\u3067\u30e1\u30c8\u30ea\u30c3\u30af\u306e\u540d\u524d\u3092\u8fd4\u3059\u5834\u5408\u3084\u3001\u30e1\u30c8\u30ea\u30c3\u30af\u540d\u3092WHERE\u53e5\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u30af\u30a8\u30ea\u3067[metric_master]\u30c6\u30fc\u30d6\u30eb\u3082\u53c2\u7167\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002SHOW\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u3044\u6163\u308c\u3066\u3044\u3066\u305d\u308c\u304c\u8fd4\u3059\u60c5\u5831\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u306a\u308c\u3070\u3001[metric_master]\u30c6\u30fc\u30d6\u30eb\u306e\u5404\u884c\u306e\u610f\u5473\u3082\u7c21\u5358\u306b\u7406\u89e3\u3067\u304d\u307e\u3059\u3002<\/li>\n<\/ul>\n

    \u6ce8\u610f<\/h4>\n

    \u3053\u3053\u3067\u2018\u30e1\u30c8\u30ea\u30c3\u30af\u2019\u306f\u3001SHOW\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3067\u8fd4\u308b\u96e2\u6563\u5024\u306e\u610f\u5473\u3067\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\uff08SHOW GLOBAL VARIABLES\u3001SHOW GLOBAL STATUS\u3001SHOW SLAVE STATUS\u306a\u3069\uff09\u3002SQL Diagnostic Manager\u304cWeb\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3067\u5b9f\u884c\u3059\u308b\u8a08\u7b97\u306f\u3001\u3069\u306e\u3088\u3046\u306a\u8a08\u7b97\u3067\u3082\u4fdd\u5b58\u306e\u5f8c\u3067\u3042\u308a\u3001\u524d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305f\u3060\u3057\u3001\u30e1\u30c8\u30ea\u30c3\u30af\u3092INSERTED\u3059\u308b\u5834\u5408\u306f\u3001\u540c\u3058\u30e1\u30c8\u30ea\u30c3\u30af\u306b\u3064\u3044\u3066\u305d\u306e\u6700\u65b0\u306e\u4fdd\u5b58\u5024\u3092\u691c\u7d22\u3057\u3066\u3001\u5dee\u5206\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u3001\u4fdd\u5b58\u524d\u306b\u8a08\u7b97\u30921\u56de\u5b9f\u884c\u3057\u307e\u3059\u3002\u73fe\u5728\u5024\u3068\u3001\u3053\u306e\u5dee\u5206\u306e\u4e21\u65b9\u3068\u3082\u4fdd\u5b58\u3055\u308c\u307e\u3059\uff08\u305d\u308c\u305e\u308c[metric_now]\u5217\u3068[metric_diff]\u5217\u306b\uff09\u3002<\/p>\n

    \u4ee5\u4e0a\u306e\u3059\u3079\u3066\u306e\u51e6\u7406\u304c\u30af\u30a8\u30ea\u3067\u5b9f\u884c\u3055\u308c\u308b\u69d8\u5b50\u3092\u3001\u308f\u304b\u308a\u3084\u3059\u3044\u4f8b\u3067\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\uff1a<\/p>\n

    \"\"<\/p>\n

    \u3053\u308c\u306f\u3001\u30b0\u30e9\u30d5\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306b\u5b9f\u969b\u306b\u5b9f\u884c\u3059\u308b\u30af\u30a8\u30ea\u306e\u4f8b\uff08\u30b5\u30a4\u30ba\u306e\u5927\u304d\u306aSQLite\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u6700\u9069\u5316\u3057\u305f\u3068\u304d\uff09\u3067\u3059\u3002<\/p>\n

    \r\nSELECT metric_now\r\nFROM snapshot_master\r\nWHERE snapshot_master.metric_id = my_metric_id\r\n   AND snapshot_master.timestamp_id IN(\r\n      SELECT MAX(timestamp_id)\r\n      FROM snapshot_master\r\n      WHERE metric_id = my_metric_id\r\n      AND timestamp_id <= (\r\n         SELECT MAX(timestamp_id)\r\n         FROM timestamp_master\r\n         WHERE server_timestamp <= my_metric_timestamp)\r\n   )\r\n<\/pre>\n

    \u5b9f\u969b\u306b\u306f\u3001SQLite\u30b5\u30dd\u30fc\u30c8\u3067\u306f\u3001SUBQUERIES\u306e\u4f7f\u7528\u3092\u63a8\u5968\u3057\u3001\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30b5\u30a4\u30ba\u306e\u5927\u304d\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u6700\u5927\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u767a\u63ee\u3059\u308b\u305f\u3081\u3001SQLite\u3068\u306eJOINS\u306f\u63a8\u5968\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u3053\u306e\u3053\u3068\u306f\u3001\u79c1\u9054\u304c\u3001\u540c\u3058\u7d50\u679c\u3092\u8fd4\u3059\u3055\u307e\u3056\u307e\u306a\u30af\u30a8\u30ea\u306e\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u3067\u7d4c\u9a13\u3057\u305f\u3053\u3068\u3067\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n

    udo.data<\/h3>\n

    \u3053\u308c\u306f\u3001\u30ab\u30b9\u30bf\u30e0SQL\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08CSO\uff09\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u3059\u3002\u3053\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f\u30013\u7a2e\u985e\u306e\u8868\u304c\u3042\u308a\u307e\u3059 - \u00a0Snapshot_master\u3001Column_master\u3001timestamp_master\u3002<\/p>\n

    \r\nCREATE TABLE [column_master]\r\n   (id INTEGER NOT NULL PRIMARY KEY,    \r\n    timestamp_id INTEGER NOT NULL,     \r\n    udo_id INTEGER NOT NULL,    \r\n    key_column_value VARCHAR(255),    \r\n    column VARCHAR(255),\r\n    UNIQUE([udo_id], [key_column_value], [column], [timestamp_id]));\r\n<\/pre>\n
    \r\nCREATE TABLE [snapshot_master] ([timestamp_id] INTEGER NOT NULL,\r\n   [metric_id] INTEGER NOT NULL,                                            \r\n   [metric_now] TEXT,                                            \r\n   [metric_diff] TEXT,                                            \r\n   PRIMARY KEY (metric_id, timestamp_id));\r\n<\/pre>\n
    \r\nCREATE TABLE [timestamp_master] (\r\n   [timestamp_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\r\n   [server_timestamp] INTEGER,                                            \r\n   [server_start_time] INTEGER,                                             \r\n   [server_uptime] INTEGER,                                            \r\n   [server_uptime_diff] INTEGER,                                            \r\n   [server_is_connected] INTEGER, [udo_id] INTEGER);\r\n<\/pre>\n

    events.data<\/h3>\n

    \u3053\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u306f\u3001SQL Diagnostic Manager\u306e\u30a4\u30d9\u30f3\u30c8\u306b\u95a2\u3059\u308b\u60c5\u5831\u3092\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n

    CREATE TABLE [events]  (id INTEGER PRIMARY KEY AUTOINCREMENT,                                    \r\n   first_seen INTEGER(5) NOT NULL,                                     \r\n   last_seen INTEGER(5) NOT NULL,                                     \r\n   down_count INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   server_id VARCHAR(255) NOT NULL,                                     \r\n   server_name VARCHAR(255) NOT NULL,                                     \r\n   group_id INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   counter_id INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   grp VARCHAR(255),                                     \r\n   name VARCHAR(255),                                    \r\n   sampling_time_frame VARCHAR(255),                                     \r\n   type INTEGER NOT NULL DEFAULT 0,                                     \r\n   threshold VARCHAR(255),                                     \r\n   value VARCHAR(255),                                     \r\n   advice TEXT,                                     \r\n   mail_alert VARCHAR(10) NOT NULL DEFAULT '',                                     \r\n   down_count_override INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   notify_stable_override VARCHAR(10) NOT NULL DEFAULT '',                                     \r\n   smtp_alert_cnt INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   snmp_alert_cnt INTEGER(5) NOT NULL DEFAULT 0,                                     \r\n   ignored_timestamp INTEGER NOT NULL DEFAULT 0);\r\n<\/pre>\n
    CREATE TABLE [timestamp_master](\r\n   [timestamp_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\r\n   [server_timestamp] INTEGER UNIQUE);<\/pre>\n","protected":false},"excerpt":{"rendered":"

    mysql.data\u3068system.data \u3053\u306e2\u3064\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9… <\/p>\n