{"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":"
\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>\nCREATE INDEX IF NOT EXISTS [timestamp_id_index] ON [snapshot_master] ([timestamp_id])<\/pre>\nCREATE 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>\nCREATE 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
\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>\nevents.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>\nCREATE 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