{"id":12931,"date":"2022-05-18T22:13:35","date_gmt":"2022-05-18T14:13:35","guid":{"rendered":"https:\/\/fgchen.com\/wpedu\/?p=12931"},"modified":"2026-03-28T22:41:34","modified_gmt":"2026-03-28T14:41:34","slug":"%e3%80%90iot-grafana%e3%80%91%e5%9c%a8mysql%e5%8c%af%e5%85%a5%e6%b8%ac%e8%a9%a6%e8%b3%87%e6%96%99%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2022\/05\/%e3%80%90iot-grafana%e3%80%91%e5%9c%a8mysql%e5%8c%af%e5%85%a5%e6%b8%ac%e8%a9%a6%e8%b3%87%e6%96%99%e9%9b%86%e5%90%88\/","title":{"rendered":"\u3010IoT-Grafana\u3011\u5728MySQL\u532f\u5165\u6e2c\u8a66\u8cc7\u6599\u96c6\u5408"},"content":{"rendered":"<h2>Step 1:\u627e\u8cc7\u6599\u96c6<\/h2>\r\n\u70ba\u4e86\u5b78\u7fd2Grafana\uff0c\u6211\u5011\u9700\u8981\u4e00\u4e9b\u8cc7\u6599\u4f86\u7df4\u7fd2\uff0c\u6211\u627e\u5230\u4e86\u4e00\u500b\u53ef\u4ee5\u4e0b\u8f09\u8cc7\u6599\u7684\u5730\u65b9\uff1a<a href=\"https:\/\/data.world\/\" target=\"_blank\" rel=\"noopener\">data.world<\/a> (\u9700\u8981\u8a3b\u518a\u624d\u80fd\u700f\u89bd\u8cc7\u6599)\r\n\r\n\u53ef\u4ee5\u4e0b\u641c\u5c0b\u627e&#8221;Iot&#8221;\uff1a\r\n\r\nhttps:\/\/data.world\/search?context=community&#038;q=type%3Adataset+AND+IOT&#038;type=resources\r\n\r\n\u6211\u627e\u5230\u4e00\u500b&#8221;<a href=\"https:\/\/data.world\/cityofchicago\/beach-water-quality-automated-sensors\" target=\"_blank\" rel=\"noopener\">Beach Water Quality &#8211; Automated Sensors<\/a>&#8220;\u8cc7\u6599\u96c6\u5408\u3002\r\n\r\n\u9019\u662f\u4e00\u500b\u6d77\u7058\u7684\u6c34\u8cea\u76e3\u6e2c\u8cc7\u6599\r\n\r\n\u4e0b\u8f09csv\u6a94\u6848\uff1abeach-water-quality-automated-sensors-1.csv\r\n\r\n\u6253\u958bcsv\u6a94\u5f8c\uff0c\u767c\u73fe\u670910\u500b\u6b04\u4f4d\u53ca\u8cc7\u6599(\u50c5\u5217\u6578\u7b46)\r\n<table style=\"border-collapse: collapse;width: 96.4786%;height: 80px\" border=\"0\" width=\"720\" cellspacing=\"0\" cellpadding=\"0\">\r\n<tbody>\r\n<tr style=\"height: 16.5pt\">\r\n<td style=\"height: 16px;width: 11.0121%;text-align: center\" width=\"72\" height=\"22\">Beach Name<\/td>\r\n<td style=\"width: 18.2333%;text-align: center;height: 16px\" width=\"72\">Measurement Timestamp<\/td>\r\n<td style=\"width: 3.8165%;text-align: center;height: 16px\" width=\"72\">Water Temperature<\/td>\r\n<td style=\"width: 4.88435%;text-align: center;height: 16px\" width=\"72\">Turbidity<\/td>\r\n<td style=\"width: 4.95889%;text-align: center;height: 16px\" width=\"72\">Transducer Depth<\/td>\r\n<td style=\"width: 4.54681%;text-align: center;height: 16px\" width=\"72\">Wave Height<\/td>\r\n<td style=\"width: 4.65959%;text-align: center;height: 16px\" width=\"72\">Wave Period<\/td>\r\n<td style=\"width: 4.18535%;text-align: center;height: 16px\" width=\"72\">Battery Life<\/td>\r\n<td style=\"width: 13.9461%;text-align: center;height: 16px\" width=\"72\">Measurement Timestamp Label<\/td>\r\n<td style=\"width: 76.668%;text-align: center;height: 16px\" width=\"72\">Measurement ID<\/td>\r\n<\/tr>\r\n<tr style=\"height: 16.5pt\">\r\n<td style=\"height: 16px;width: 11.0121%\" height=\"22\">Montrose Beach<\/td>\r\n<td style=\"width: 18.2333%;height: 16px\">08\/30\/2013 08:00:00 AM<\/td>\r\n<td style=\"width: 3.8165%;height: 16px\" align=\"right\">20.3<\/td>\r\n<td style=\"width: 4.88435%;height: 16px\" align=\"right\">1.18<\/td>\r\n<td style=\"width: 4.95889%;height: 16px\" align=\"right\">0.891<\/td>\r\n<td style=\"width: 4.54681%;height: 16px\" align=\"right\">0.08<\/td>\r\n<td style=\"width: 4.65959%;height: 16px\" align=\"right\">3<\/td>\r\n<td style=\"width: 4.18535%;height: 16px\" align=\"right\">9.4<\/td>\r\n<td style=\"width: 13.9461%;height: 16px\">8\/30\/2013 8:00 AM<\/td>\r\n<td style=\"width: 76.668%;height: 16px\">MontroseBeach201308300800<\/td>\r\n<\/tr>\r\n<tr style=\"height: 16.5pt\">\r\n<td style=\"height: 16px;width: 11.0121%\" height=\"22\">Ohio Street Beach<\/td>\r\n<td style=\"width: 18.2333%;height: 16px\">05\/26\/2016 01:00:00 PM<\/td>\r\n<td style=\"width: 3.8165%;height: 16px\" align=\"right\">14.4<\/td>\r\n<td style=\"width: 4.88435%;height: 16px\" align=\"right\">1.23<\/td>\r\n<td style=\"width: 4.95889%;height: 16px\"><\/td>\r\n<td style=\"width: 4.54681%;height: 16px\" align=\"right\">0.111<\/td>\r\n<td style=\"width: 4.65959%;height: 16px\" align=\"right\">4<\/td>\r\n<td style=\"width: 4.18535%;height: 16px\" align=\"right\">12.4<\/td>\r\n<td style=\"width: 13.9461%;height: 16px\">05\/26\/2016 1:00 PM<\/td>\r\n<td style=\"width: 76.668%;height: 16px\">OhioStreetBeach201605261300<\/td>\r\n<\/tr>\r\n<tr style=\"height: 16.5pt\">\r\n<td style=\"height: 16px;width: 11.0121%\" height=\"22\">Calumet Beach<\/td>\r\n<td style=\"width: 18.2333%;height: 16px\">09\/03\/2013 04:00:00 PM<\/td>\r\n<td style=\"width: 3.8165%;height: 16px\" align=\"right\">23.2<\/td>\r\n<td style=\"width: 4.88435%;height: 16px\" align=\"right\">3.63<\/td>\r\n<td style=\"width: 4.95889%;height: 16px\" align=\"right\">1.201<\/td>\r\n<td style=\"width: 4.54681%;height: 16px\" align=\"right\">0.174<\/td>\r\n<td style=\"width: 4.65959%;height: 16px\" align=\"right\">6<\/td>\r\n<td style=\"width: 4.18535%;height: 16px\" align=\"right\">9.4<\/td>\r\n<td style=\"width: 13.9461%;height: 16px\">9\/3\/2013 4:00 PM<\/td>\r\n<td style=\"width: 76.668%;height: 16px\">CalumetBeach201309031600<\/td>\r\n<\/tr>\r\n<tr style=\"height: 16.5pt\">\r\n<td style=\"height: 16px;width: 11.0121%\" height=\"22\">Calumet Beach<\/td>\r\n<td style=\"width: 18.2333%;height: 16px\">05\/28\/2014 12:00:00 PM<\/td>\r\n<td style=\"width: 3.8165%;height: 16px\" align=\"right\">16.2<\/td>\r\n<td style=\"width: 4.88435%;height: 16px\" align=\"right\">1.26<\/td>\r\n<td style=\"width: 4.95889%;height: 16px\" align=\"right\">1.514<\/td>\r\n<td style=\"width: 4.54681%;height: 16px\" align=\"right\">0.147<\/td>\r\n<td style=\"width: 4.65959%;height: 16px\" align=\"right\">4<\/td>\r\n<td style=\"width: 4.18535%;height: 16px\" align=\"right\">11.7<\/td>\r\n<td style=\"width: 13.9461%;height: 16px\">5\/28\/2014 12:00 PM<\/td>\r\n<td style=\"width: 76.668%;height: 16px\">CalumetBeach201405281200<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\u9019\u5e7e\u500b\u6b04\u4f4d\u7684\u610f\u7fa9\u5f9e\u540d\u7a31\u53ef\u4ee5\u5f97\u77e5\uff1a\r\n\r\nBeach Name\uff1a\u6d77\u7058\u540d\u7a31\uff0cMeasurement Timestamp\uff1a\u6e2c\u91cf\u6642\u9593\uff0cWater Temperature\uff1a\u6c34\u6eab\uff0cTurbidity\uff1a\u6fc1\u5ea6\uff0cTransducer Depth\uff1a\u50b3\u611f\u5668\u6df1\u5ea6\uff0cWave Height\uff1a\u6d77\u6d6a\u9ad8\u5ea6\uff0cWave Period\uff1a\u6d77\u6d6a\u9031\u671f\uff0cBattery Life\uff1a\u96fb\u6c60\u58fd\u547d\uff0cMeasurement Timestamp Label\uff1a\u540cMeasurement Timestamp\uff0cMeasurement ID\uff1a\u6e2c\u91cfID\u3002\r\n\r\n&nbsp;\r\n<h2>Step 2:<\/h2>\r\n\u6211\u5011\u8981\u6839\u64da\u4e0a\u9762\u7684\u6b04\u4f4d\uff0c\u5728MySQL\u4e0a\u5efa\u7acb\u8cc7\u6599\u3002 (\u7279\u5225\u6ce8\u610f\uff1a\u4e0a\u9762\u6e2c\u91cf\u7684\u6642\u9593\u662f\u5b57\u4e32\uff0c\u5728MySQL\u88cf\u662fvarchar\u8cc7\u6599\u578b\u614b\uff0c\u4f46\u662f\uff0c\u6211\u5011\u8981\u628a\u9019\u500b\u6b04\u4f4d\u7684\u8cc7\u6599\u8f49\u63db\u70baDateTime\u6642\u9593\u8cc7\u6599\u578b\u614b)\r\n\r\n\u5230PHPMyAdmin\u5efa\u7acb\u8cc7\u6599\u5eabmyiot\u8207\u8cc7\u6599\u8868\u683cbeach_water_quality\uff0c\u4e26\u4e14\u5efa\u7acb10\u500b\u6b04\u4f4d\uff0c\u6b04\u4f4d\u540d\u7a31\u6839\u64dacsv\u8868\u683c\u88cf\u7684\u7b2c\u4e00\u5217\u6b04\u4f4d\u540d\u7a31\u3002\r\n\r\nMeasurement Timestamp\u8ddfMeasurement Timestamp Label\u4e00\u958b\u59cb\u8cc7\u6599\u985e\u578b\u8a2dvarchar\uff0c\u4e4b\u5f8c\uff0c\u6211\u5011\u8981\u9032\u884c\u8f49\u63db\u6210datetime\u985e\u578b\u3002\r\n\r\n<img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-12933\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table.png\" alt=\"\" width=\"984\" height=\"502\" srcset=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table.png 984w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-300x153.png 300w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-768x392.png 768w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-600x306.png 600w\" sizes=\"(max-width: 984px) 100vw, 984px\" \/>\r\n\r\nMeasurement ID\u6211\u5011\u8a2d\u7f6e\u70baKey(Primary key\uff0c\u9375\u503c)\r\n<h2>Step 3\uff1a\u532f\u5165CSV\u8cc7\u6599\u96c6 (\u8fd14\u842c\u7b46\u8cc7\u6599\u9700\u8017\u8cbb\u4e0d\u5c11\u6642\u9593)<\/h2>\r\n<img decoding=\"async\" class=\"alignnone size-full wp-image-12935\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import.png\" alt=\"\" width=\"1348\" height=\"855\" srcset=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import.png 1348w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import-300x190.png 300w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import-1024x649.png 1024w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import-768x487.png 768w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-data-import-600x381.png 600w\" sizes=\"(max-width: 1348px) 100vw, 1348px\" \/>\r\n\r\n\u7b49\u5f85\u2026\uff0c\u5b8c\u6210\u5f8c\u700f\u89bd\u8cc7\u6599\u8868\u683c\uff1a\r\n\r\n<img decoding=\"async\" class=\"alignnone size-full wp-image-12937\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported.png\" alt=\"\" width=\"1537\" height=\"470\" srcset=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported.png 1537w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported-300x92.png 300w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported-1024x313.png 1024w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported-768x235.png 768w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-imported-600x183.png 600w\" sizes=\"(max-width: 1537px) 100vw, 1537px\" \/>\r\n<h2>Step 4\uff1a\u532f\u5b8c\u8cc7\u6599\u5f8c\uff0c\u6211\u5011\u8981\u5c07\u6642\u9593\u6b04\u4f4d\u9032\u884c\u5b57\u4e32\u8f49datetime<\/h2>\r\n\u57f7\u884cMeasurement Timestamp\u6b04\u4f4d\u7684\u8cc7\u6599\u985e\u578b\u8f49\u63db\uff1a\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">UPDATE beach_water_quality  SET `Measurement Timestamp` = str_to_date( `Measurement Timestamp`, '%m\/%d\/%Y %h:%i:%s %p')<\/pre>\r\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12938\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert.png\" alt=\"\" width=\"1391\" height=\"636\" srcset=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert.png 1391w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert-300x137.png 300w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert-1024x468.png 1024w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert-768x351.png 768w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-field-type-convert-600x274.png 600w\" sizes=\"(max-width: 1391px) 100vw, 1391px\" \/>\r\n\r\n\u4e0a\u9762\u7684\u683c\u5f0f\u5b57\u4e32\u8acb\u53c3\u8003\uff1a<a href=\"https:\/\/www.w3schools.com\/sql\/func_mysql_str_to_date.asp\" target=\"_blank\" rel=\"noopener\">MySQL STR_TO_DATE() Function<\/a>\r\n\r\n%m\/%d\/%Y %h:%i:%s %p\r\n\r\nm:\u6708\uff0cd:\u65e5\uff0cY:4\u4f4d\u6578\u5e74\uff0c h:\u6642\uff0ci:\u5206\uff0cs:\u79d2\uff0cp\u886812\u621624\u6642\u5236\r\n\r\n\u57f7\u884cMeasurement Timestamp Label\u6b04\u4f4d\u7684\u8cc7\u6599\u985e\u578b\u8f49\u63db\uff1a\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">UPDATE beach_water_quality  SET `Measurement Timestamp Label` = str_to_date( `Measurement Timestamp Label`, '%m\/%d\/%Y %h:%i %p')<\/pre>\r\n\u9019\u500bSQL\u5716\u7701\u7565\r\n\r\n\u6700\u5f8c\uff0c\u6211\u5011\u5f97\u5230\u6211\u5011\u8981\u7684\u8cc7\u6599\uff1a\r\n\r\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12939\" src=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final.png\" alt=\"\" width=\"1541\" height=\"880\" srcset=\"https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final.png 1541w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final-300x171.png 300w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final-1024x585.png 1024w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final-768x439.png 768w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final-1536x877.png 1536w, https:\/\/fgchen.com\/wpedu\/wp-content\/uploads\/2022\/05\/beach-water-quality-table-data-final-600x343.png 600w\" sizes=\"(max-width: 1541px) 100vw, 1541px\" \/>","protected":false},"excerpt":{"rendered":"<p>Step 1:\u627e\u8cc7\u6599\u96c6 \u70ba\u4e86\u5b78\u7fd2Grafana\uff0c\u6211\u5011\u9700\u8981\u4e00\u4e9b\u8cc7\u6599\u4f86\u7df4\u7fd2\uff0c\u6211\u627e\u5230\u4e86 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[256],"tags":[215],"class_list":["post-12931","post","type-post","status-publish","format-standard","hentry","category-256","tag-iot"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12931"}],"version-history":[{"count":8,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12931\/revisions"}],"predecessor-version":[{"id":13353,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12931\/revisions\/13353"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}