{"id":511,"date":"2022-11-14T21:32:08","date_gmt":"2022-11-14T13:32:08","guid":{"rendered":"http:\/\/wordpress.loc\/?p=511"},"modified":"2023-02-22T20:48:59","modified_gmt":"2023-02-22T12:48:59","slug":"esp32_ch1-5","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/11\/14\/511\/","title":{"rendered":"\u7b2c11\u7bc7 ESP32 \u8cc7\u6599\u5eab\u5b58\u53d6MySQL\u9023\u7dda"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>ESP\u5167\u5efa\u7684WiFi\u4e0a\u7db2\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5c07\u6536\u96c6\u5230\u7684\u8cc7\u6599\u5b58\u5165\u96f2\u7aef\u8cc7\u6599\u5eab\uff0c\u65b9\u4fbf\u7acb\u5373\u67e5\u770b\u5373\u6642\u72c0\u6cc1\uff0c\u800c\u4e14\u6709\u9577\u671f\u7684\u8cc7\u6599\u5f8c\u5c31\u53ef\u4ee5\u9032\u884c\u5f8c\u7e8c\u5206\u6790\u8207\u6bd4\u8f03<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">ESP32 \u8cc7\u6599\u5eab\u5b58\u53d6MySQL\u9023\u7dda\u65b9\u6cd5<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-\">\u524d\u8a00\u8aaa\u660e<\/a><\/li><li class=\"\"><a href=\"#htoc-mysql-workbench\">\u4e00\u3001\u74b0\u5883\u8a2d\u5b9a\uff1a\u5b89\u88ddMySQL\u53caworkbench<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1-mysql\">1.\u5b89\u88ddMySQL\u4f3a\u670d\u5668<\/a><\/li><li class=\"\"><a href=\"#htoc-2-workbench\">2.\u5b89\u88ddworkbench<\/a><\/li><li class=\"\"><a href=\"#htoc-3-workbench-mysql\">3.\u5c07workbench\u9023\u7dda\u5230mysql\u8cc7\u6599\u5eab<\/a><\/li><li class=\"\"><a href=\"#htoc-4-mysql\">4.\u4fee\u6539MySQL\u9060\u7aef\u9023\u7dda\u8a2d\u5b9a<\/a><\/li><li class=\"\"><a href=\"#htoc-5\">5.\u4fee\u6539\u8a8d\u8b49\u65b9\u5f0f<\/a><\/li><\/ul><\/li><li class=\"\"><a href=\"#htoc-esp32-dht11\">\u4e8c\u3001\u7dda\u8def\u4f48\u7f6e\uff1a\u9023\u63a5ESP32\u53caDHT11<\/a><\/li><li class=\"\"><a href=\"#htoc-arduino-ide\">\u4e09\u3001\u7a0b\u5f0f\u958b\u767c\uff1a\u5728Arduino IDE\u4e2d\u64b0\u5beb\u7a0b\u5f0f<\/a><ul class=\"ht_toc_child_list\"><li class=\"\"><a href=\"#htoc-1-mysql-library\">1.\u532f\u5165MySQL Library<\/a><\/li><li class=\"\"><a href=\"#htoc-2\">2.\u9023\u7dda\u6e2c\u8a66<\/a><\/li><li class=\"\"><a href=\"#htoc-3-dht11\">3.DHT11\u6e2c\u8a66<\/a><\/li><\/ul><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u524d\u8a00\u8aaa\u660e<\/h2>\n\n\n\n<p>ESP\u5167\u5efa\u7684WiFi\u4e0a\u7db2\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5c07\u6536\u96c6\u5230\u7684\u8cc7\u6599\u5b58\u5165\u96f2\u7aef\u8cc7\u6599\u5eab\uff0c\u65b9\u4fbf\u7acb\u5373\u67e5\u770b\u5373\u6642\u72c0\u6cc1\uff0c\u800c\u4e14\u6709\u9577\u671f\u7684\u8cc7\u6599\u5f8c\u5c31\u53ef\u4ee5\u9032\u884c\u5f8c\u7e8c\u5206\u6790\u8207\u6bd4\u8f03\uff0c\u4e5f\u80fd\u5728\u767c\u751f\u7570\u5e38\u6642\u767c\u51faMail, Line\u7b49\u901a\u77e5\u7ba1\u7406\u8005\uff0c\u9054\u5230\u7acb\u5373\u8655\u7406\u7684\u529f\u80fd\uff0c\u9019\u6a23\u624d\u7b97\u771f\u6b63\u767c\u63eeIoT\u88dd\u7f6e\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u672c\u7ae0\u8981\u4ecb\u7d39\u5982\u4f55\u5c07DHT11\u7684\u6eab\u6fd5\u5ea6\u7b49\u8cc7\u6599\u4e0a\u50b3\u5230\u81ea\u5df1\u5efa\u7acb\u7684\u8cc7\u6599\u5eab\uff0c\u82e5\u8b80\u8005\u6c92\u6709\u7db2\u8def\u4f3a\u670d\u5668\u53ef\u4ee5\u5efa\u7acbMySQL\uff0c\u5247\u53ef\u8df3\u904e\u672c\u7ae0\uff0c\u76f4\u63a5\u95b1\u8b80\u4e0b\u4e00\u7ae0\u300cESP32 \u8cc7\u6599\u5eab\u5b58\u53d6ThingSpeak\u5716\u8868\u88fd\u4f5c\u300d\uff0c\u4e0d\u9700\u8981\u81ea\u5df1\u5efa\u7acb\u8cc7\u6599\u5eab\uff0c\u7562\u7adf\u8cc7\u6599\u5eab\u4f3a\u670d\u5668\u7684\u7ba1\u7406\u7dad\u8b77\u554f\u984c\u4e4b\u5916\uff0c\u9084\u6709\u7db2\u8def\u9023\u7ddaIP\u3001DDNS\u3001NAT\u3001\u865b\u64ec\u4f3a\u670d\u5668\u3001\u9023\u63a5\u57e0\u8f49\u9001\u7b49\u7db2\u8def\u76f8\u95dc\u7684\u77e5\u8b58\uff0c\u518d\u52a0\u4e0aSQL\u8cc7\u6599\u5eab\u7684\u7dad\u8b77\u8207\u8a9e\u6cd5\u4e5f\u662f\u4e00\u500b\u5f88\u5927\u7684\u8b70\u984c\u3002\u4e0d\u904e\u81ea\u5df1\u5efa\u7acb\u8cc7\u6599\u5eab\u7684\u597d\u8655\u5247\u662f\u8cc7\u6599\u5132\u5b58\u3001\u4f7f\u7528\u3001\u53ca\u5f8c\u7e8c\u7ba1\u7406\u8207\u67e5\u8a62\u90fd\u662f\u7531\u81ea\u5df1\u638c\u63a7\uff0c\u76f8\u5c0d\u66f4\u52a0\u81ea\u7531\uff0c\u9019\u4e5f\u662f\u5f88\u591a\u9032\u968e\u73a9\u5bb6\u9078\u64c7\u9019\u6a23\u4f5c\u6cd5\u7684\u539f\u56e0\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u8981\u8aaa\u660e\u7684\u5247\u662f\u672c\u7bc7\u4ecb\u7d39\u7684\u65b9\u6cd5\u662f\u8b93ESP32\u8207MySQL\u76f4\u63a5\u5efa\u7acb\u9023\u63a5\uff0c\u800c\u4e0d\u662f\u66f4\u6b63\u5f0f\u7684\u4e09\u5c64\u5f0f(Three Tier)\u4f5c\u6cd5\uff0c\u4e5f\u5c31\u662f\u8b93ESP32\u900f\u904eHTTP Post\u6216Get\u50b3\u8cc7\u6599\u5230AP Server\uff0c\u800cAP Server\u518d\u5b58\u5165\u8cc7\u6599\u5eab\u4e2d\u7684\u9593\u63a5\u9023\u7dda\u65b9\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-mysql-workbench\">\u4e00\u3001\u74b0\u5883\u8a2d\u5b9a\uff1a\u5b89\u88ddMySQL\u53caworkbench<\/h2>\n\n\n\n<p>\u672c\u7ae0\u4f7f\u7528MySQL\u6700\u5927\u7684\u597d\u8655\u662f\uff0c\u4ed6\u662f\u514d\u8cbb\u7684\uff0c\u57f7\u884c\u6548\u80fd\u4e5f\u4e0d\u5dee\uff0c\u53e6\u5916\u5c31\u662fworkbench\uff0c\u9019\u662f\u61f6\u4eba\u7684\u798f\u97f3\uff0c\u5982\u679c\u4f60\u8ddf\u6211\u4e00\u6a23\uff0c\u5c0dcmd\u754c\u9762\u4e0d\u719f\u6089\uff0c\u4f60\u4e00\u5b9a\u8981\u5b89\u88ddworkbench\uff0c\u4ed6\u63d0\u4f9b\u4f60\u5b8c\u6574\u7684MySQL\u5716\u5f62\u754c\u9762\u64cd\u4f5c\u6a21\u5f0f\uff0c\u771f\u5fc3\u63a8\u85a6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-1-mysql\">1.\u5b89\u88ddMySQL\u4f3a\u670d\u5668<\/h3>\n\n\n\n<p>\u5b89\u88dd\u65b9\u5f0f\u7db2\u8def\u975e\u5e38\u591a\u4ecb\u7d39\uff0c\u8acb\u81ea\u884cgoogle\uff0c\u6216\u53c3\u8003\u9019\u7bc7\uff1a <a href=\"https:\/\/jerrynest.io\/windows-mysql-installer\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/jerrynest.io\/windows-mysql-installer\/ <\/a><\/p>\n\n\n\n<p>\u4e0b\u8f09\u7684\u7db2\u5740\uff1a <a href=\"https:\/\/dev.mysql.com\/downloads\/installer\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/dev.mysql.com\/downloads\/installer\/ <\/a><\/p>\n\n\n\n<p>\u984c\u5916\u8a71\uff0c\u5982\u679c\u4f60\u60f3\u7528cluster\u7248\uff0c\u53ef\u53c3\u8003\u672c\u4eba\u672c\u7bc7\u6587\u7ae0\uff1a <a href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/14\/sql\/\">Mysql Cluster \u5be6\u505a<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-2-workbench\">2.\u5b89\u88ddworkbench<\/h3>\n\n\n\n<p>\u4e0b\u8f09\u7db2\u5740\uff1a <a href=\"https:\/\/www.mysql.com\/products\/workbench\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.mysql.com\/products\/workbench\/<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-3-workbench-mysql\">3.\u5c07workbench\u9023\u7dda\u5230mysql\u8cc7\u6599\u5eab<\/h3>\n\n\n\n<p>workbench\u5b89\u88dd\u5b8c\u7562\u5f8c\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u900f\u904eworkbench\u9032\u5165\u8cc7\u6599\u5eab\uff0c\u4ee5\u9032\u884c\u8a2d\u5b9a\uff0c\u5305\u62ec\u5efa\u7acb\u65b0\u7684\u8cc7\u6599\u5eab\u6b04\u4f4d\u4ee5\u53ca\u958b\u653e\u8b93IoT\u53ef\u9023\u5165\u66f4\u65b0\u8cc7\u6599\uff0c\u8b93Arduino\u53ef\u4ee5WiFi\u9060\u7aef\u66f4\u65b0\u8cc7\u6599\u5eab<\/p>\n\n\n\n<p>3.1 Workbench\u9023\u7dda<\/p>\n\n\n\n<p>\u4e00\u822cWorkbench\u5b89\u88dd\u5b8c\u7562\u90fd\u6703\u5efa\u7acb\u4e00\u500b\u9023\u7dda\u662f\u76f4\u63a5\u9023\u7dda\u5230\u672c\u6a5f\u7aefMySQL\uff0c\u540d\u7a31\u662f127.0.0.1\u76f4\u63a5\u6253\u958b\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1558368836-93062525.png?resize=841%2C615&#038;ssl=1\" alt=\"\" width=\"841\" height=\"615\"\/><figcaption class=\"wp-element-caption\">Workbench\u5b89\u88dd\u5b8c\u7562\u756b\u9762<\/figcaption><\/figure>\n\n\n\n<p>3.2 \u5efa\u7acb\u65b0\u8cc7\u6599\u5eab<\/p>\n\n\n\n<p>\u9ede\u9078\u5de6\u4e0a\u65b9\u7684Create new schema\u5716\u793a\uff0c\u4ee5\u5efa\u7acb\u8cc7\u6599\u5eab\uff0c\u5c07\u5b58\u653eDHT11\u50b3\u5165\u7684\u6eab\u6fd5\u5ea6\u8cc7\u6599\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583595544-2689001350.png?resize=839%2C591&#038;ssl=1\" alt=\"\" width=\"839\" height=\"591\"\/><figcaption class=\"wp-element-caption\">\u9ede\u9078\u5de6\u4e0a\u65b9\u7684Create new schema<\/figcaption><\/figure>\n\n\n\n<p>\u8cc7\u6599\u5eab\u540d\u7a31\u53ef\u81ea\u5df1\u53d6\u540d\uff0c\u4f46\u4e0d\u53ef\u7528\u4e2d\u6587\uff0c\u4f8b\u5982\u7b46\u8005\u5c07\u65b0\u7684\u8cc7\u6599\u5eab\u53d6\u540d\u70ba\u300ctempandhumd\u300d\uff0c\u4ee3\u8868\u6536\u53d6\u7684\u662f\u6eab\u5ea6\u53ca\u6fd5\u5ea6\uff0c\u5b8c\u6210\u540d\u7a31\u8f38\u5165\u5f8cCollation\u4f9d\u7167\u9810\u8a2d\u503cServer Default\u5373\u53ef\uff0c\u6700\u5f8c\u6309\u53f3\u4e0b\u89d2\u7684Apply\u5373\u6703\u770b\u5230\u5b8c\u6210\u7684\u8996\u7a97\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583595414-3242915884.png?resize=841%2C732&#038;ssl=1\" alt=\"\" width=\"841\" height=\"732\"\/><figcaption class=\"wp-element-caption\">\u8cc7\u6599\u5eab\u547d\u540d\u756b\u9762<\/figcaption><\/figure>\n\n\n\n<p>\u518d\u4f86\u5efa\u7acb\u8cc7\u6599\u8868\uff0c\u5728\u525b\u5efa\u597d\u7684\u8cc7\u6599\u5eab\u524d\u65b9+\u865f\u9ede\u958b\uff0c\u5728table\u4e0a\u6309\u53f3\u9375\uff0c\u9078\u64c7Create Table\uff0c\u5efa\u7acb\u8cc7\u6599\u8868\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583595851-702813681.png?resize=840%2C871&#038;ssl=1\" alt=\"\" width=\"840\" height=\"871\"\/><figcaption class=\"wp-element-caption\">Create Table\u5efa\u7acb\u8cc7\u6599\u8868<\/figcaption><\/figure>\n\n\n\n<p>\u5efa\u7acb\u7684\u8cc7\u6599\u8868\u540d\u7a31\u70ba\u300cdatalog\u300d\uff0c\u6b04\u4f4d\u9664\u4e86\u6eab\u5ea6\u3001\u6fd5\u5ea6\u4e4b\u5916\uff0c\u53ef\u7528\u81ea\u52d5\u7de8\u865f\u7576\u4f5c\u4e3b\u9375\uff0c\u6700\u5f8c\u5728\u7d66\u4e00\u500b\u66f4\u65b0\u6642\u9593\uff0c\u56e0\u6b64\u6709\u56db\u500b\u6b04\u4f4d\u8a2d\u5b9a\u5982\u4e0b<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>id\uff1a\u6574\u6578\uff0c\uff08\u4ee3\u8868\u81ea\u52d5\u7de8\u865f\u6b04\u4f4d\uff09<\/li>\n\n\n\n<li>temp\uff1a\u6574\u6578\uff08\u4ee3\u8868\u6eab\u5ea6\u6b04\u4f4d\uff09<\/li>\n\n\n\n<li>humd\uff1a\u6574\u6578\uff08\u4ee3\u8868\u6ebc\u5ea6\u6b04\u4f4d\uff09<\/li>\n\n\n\n<li>updatetime\uff1atimestamp\uff08\u4ee3\u8868\u8cc7\u6599\u6642\u9593\u6b04\u4f4d\uff09\uff0c\u4e26\u7d66\u4e88\u9810\u8a2d\u503c\uff1aCURRENT_TIMESTAMP\uff0c\u76ee\u7684\u662f\u9019\u6a23\u7576\u8cc7\u6599\u65b0\u589e\u6642\uff0c\u76f4\u63a5\u7d66\u63d2\u5165\u8cc7\u6599\u7684\u6642\u9593\u3002<br>\u7136\u6709\u56db\u500b\u6b04\u4f4d\uff0c\u4f46\u5be6\u969b\u4e0a\u6211\u5011\u50c5\u9808\u7d66temp\u8ddfhumd\u5373\u53ef\uff0cid\u8207updatetime\u90fd\u662fsql\u8cc7\u6599\u5eab\u76f4\u63a5\u7d66\u503c\u5f97\u3002\u9019\u6a23\u6bd4\u8f03\u7c21\u55ae\u3002<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583595901-590178383.png?resize=840%2C301&#038;ssl=1\" alt=\"\" width=\"840\" height=\"301\"\/><figcaption class=\"wp-element-caption\">\u8cc7\u6599\u8868\u6b04\u4f4d\u8a2d\u5b9a<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-4-mysql\">4.\u4fee\u6539MySQL\u9060\u7aef\u9023\u7dda\u8a2d\u5b9a<\/h3>\n\n\n\n<p>\u56e0\u70ba\u5b89\u5168\u8003\u91cf\uff0c\u9810\u8a2dMySQL\u53ea\u5141\u8a31\u672c\u6a5f\u767b\u5165\u800c\u4e0d\u80fd\u5916\u90e8\u9023\u5165\uff0c\u4f46\u662f\u6211\u5011\u7684Arduino IoT\u88dd\u7f6e\u662f\u5c6c\u65bc\u5916\u90e8\u88dd\u7f6e\uff0c\u56e0\u6b64\u5fc5\u9808\u5c07\u4f7f\u7528\u8005\u958b\u653e\u5916\u90e8\u767b\u5165\uff0c\u9019\u88e1\u5fc5\u9808\u8aaa\u660e\uff0c\u9019\u6a23\u7684\u4f5c\u6cd5\u662f\u6709\u5b89\u5168\u6027\u554f\u984c\u7684\uff0c\u53ea\u5efa\u8b70\u81ea\u5df1\u5efa\u7acb\u4f3a\u670d\u5668\u4f86\u6e2c\u8a66\uff0c\u4e0d\u8981\u62ff\u516c\u53f8\u6216\u5b78\u6821\u7684\u4f3a\u670d\u5668\u4f86\u6e2c\u8a66\u3002<br><br>\u4fee\u6539root\u4f7f\u7528\u8005\u7531\u539f\u672c\u7684localhost\u6539\u70ba%\uff0c\u4ee3\u8868\u8a72\u4f7f\u7528\u8005\u53ef\u4ee5\u5f9e\u7db2\u8def\u4e0a\u4efb\u4f55\u5730\u9ede\u9023\u9032\u8cc7\u6599\u5eab\u4f86\u9032\u884c\u4fee\u6539\u3002 \u5b8c\u6210\u5f8c\u6309\u4e0b\u65b9\u7684Apply\u5373\u53ef\u5b58\u6a94\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583597867-1103506611.png?resize=840%2C455&#038;ssl=1\" alt=\"\" width=\"840\" height=\"455\"\/><figcaption class=\"wp-element-caption\">\u4fee\u6539root\u4f7f\u7528\u8005\u6b0a\u9650<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-5\">5.\u4fee\u6539\u8a8d\u8b49\u65b9\u5f0f<\/h3>\n\n\n\n<p>\u56e0\u70ba\u5f8c\u7e8c\u6709\u7db2\u53cb\u53cd\u61c9\u8cc7\u6599\u50b3\u905e\u5931\u6557\uff0c\u932f\u8aa4\u8a0a\u606f\u662f\u300cClient does not support authentication protocol requested by server\u300d\uff0c\u7d93\u67e5\u8a62\u662f\u56e0\u70baMySQL 8.0\u7684\u8a8d\u8b49\u65b9\u5f0f\u5df2\u7d93\u5347\u7d1a\uff0c\u4f46\u76ee\u524dArduino\u7684MySQL\u51fd\u5f0f\u5eab\u4e26\u672a\u5347\u7d1a\uff0c\u76ee\u524d\u7684\u65b9\u5f0f\uff0c\u66ab\u6642\u5c07MySQL\u7684\u9023\u7dda\u8a8d\u8b49\u65b9\u5f0f\u964d\u7d1a\uff0c\u4f5c\u6cd5\u70ba\u958b\u555fMySQL Command\u8996\u7a97\uff0c\u4e26\u8f38\u5165\u4ee5\u4e0b\u6307\u4ee4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'SQLpassword';<\/code><\/pre>\n\n\n\n<p>\u9019\u88e1\u7684SQLpassword\u4ee3\u8868\u4f60root\u7684\u5bc6\u78bc\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583611261-1877570789.png?resize=841%2C289&#038;ssl=1\" alt=\"\" width=\"841\" height=\"289\"\/><figcaption class=\"wp-element-caption\">\u5c07MySQL\u7684\u9023\u7dda\u8a8d\u8b49\u65b9\u5f0f\u964d\u7d1a<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-esp32-dht11\">\u4e8c\u3001\u7dda\u8def\u4f48\u7f6e\uff1a\u9023\u63a5ESP32\u53caDHT11<\/h2>\n\n\n\n<p>\u672c\u90e8\u4efd\u9023\u63a5DHT11\u53caESP32\uff0c\u672c\u8acb\u53c3\u8003\u524d\u7bc7\uff1aESP32 \u6eab\u6fd5\u5ea6\u986f\u793a\u5668(DHT11+1602 LCD)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-arduino-ide\">\u4e09\u3001\u7a0b\u5f0f\u958b\u767c\uff1a\u5728Arduino IDE\u4e2d\u64b0\u5beb\u7a0b\u5f0f<\/h2>\n\n\n\n<p>\u672c\u90e8\u4efd\u5247\u662f\u5728Aruino IDE\u4e2d\u64b0\u5beb\u7a0b\u5f0f\uff0c\u5982\u4f55\u5c07\u8cc7\u6599\u4e0a\u50b3MySQL\uff0c\u6211\u5011\u5c07\u76f4\u63a5\u4f7f\u7528MySQL\u7684library\u9032\u884c\u4e0a\u50b3\uff0c\u4e26\u8aaa\u660e\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-1-mysql-library\">1.\u532f\u5165MySQL Library<\/h3>\n\n\n\n<p>\u5b89\u88dd&#8221;MySQL connector arduino&#8221; by Dr. Charles Bell\uff0c\u4f9d\u7167\u4e0b\u5716\u958b\u555f\u7ba1\u7406\u51fd\u5f0f\u5eab\u529f\u80fd\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1558371320-2143862187.png?resize=840%2C645&#038;ssl=1\" alt=\"\" width=\"840\" height=\"645\"\/><figcaption class=\"wp-element-caption\">\u958b\u555fAruino IDE\u4e2d\u7ba1\u7406\u51fd\u5f0f\u5eab<\/figcaption><\/figure>\n\n\n\n<p>\u641c\u5c0b\u95dc\u9375\u5b57MySQL \uff0c\u5373\u53ef\u627e\u5230\u6240\u9700\u7684library\uff0c\u9ede\u9078\u53f3\u5074\u7684Install\u5b89\u88dd\u6309\u9215\u628a\u4ed6\u5b89\u88dd\u8d77\u4f86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583596512-965094627.png?resize=841%2C470&#038;ssl=1\" alt=\"\" width=\"841\" height=\"470\"\/><figcaption class=\"wp-element-caption\">\u5b89\u88ddMySQL\u7a0b\u5f0f\u5eab<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-2\">2.\u9023\u7dda\u6e2c\u8a66<\/h3>\n\n\n\n<p>\u63a5\u4e0b\u4f86\u5c31\u53ef\u4ee5\u5148\u6e2c\u8a66\u5c07\u503c\u50b3\u5165\u904e\u7a0b\u662f\u5426\u6b63\u5e38\uff0c\u5148\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u9032\u884c\u6e2c\u8a66\uff0c\u5176\u4e2d\u6eab\u5ea6\u53ca\u6fd5\u5ea6\u662f\u76f4\u63a5\u9375\u5165\uff0c\u76ee\u7684\u5728\u6e2c\u8a66\u7db2\u8def\u9023\u7dda\u662f\u5426\u6b63\u5e38\u3002\u8981\u4fee\u6539\u7684\u90e8\u4efd\u5305\u62ec\u7121\u7dda\u7db2\u8def\u7684SSID\u53ca\u5bc6\u78bc\uff0c\u9084\u6709SQL\u8cc7\u6599\u5eab\u7684IP\u4f4d\u5740\u53ca\u5e33\u865f\u5bc6\u78bc\uff0c\u9019\u88e1\u6709\u4e00\u500b\u5730\u65b9\u8981\u6ce8\u610f\u7684\u662fserver_addr\u662f\u7528\u300c,\u300d\u505a\u5340\u9694\uff0c\u800c\u4e0d\u662f\u50b3\u7d71\u7684\u300c.\u300d\u505a\u5340\u9694\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/MySQL\u9023\u7dda\u6e2c\u8a66\uff0c\u624b\u52d5\u5beb\u5165\u4e00\u500b\u6eab\u5ea6\u53ca\u6fd5\u5ea6\u8cc7\u6599\u505a\u6e2c\u8a66\n#include &lt;WiFi.h&gt;\n#include &lt;MySQL_Connection.h&gt;\n#include &lt;MySQL_Cursor.h&gt;\n\nconst char ssid&#91;]     = \"SSID\";\/\/ change to your WIFI SSID\nconst char password&#91;] = \"SSIDPassword\";\/\/ change to your WIFI Password\nIPAddress server_addr(192,168,1,107);\/\/ change to you server ip, note its form split by \",\" not \".\"\nint MYSQLPort =3306;   \/\/mysql port default is 3306\nchar user&#91;] = \"root\";\/\/ Your MySQL user login username(default is root),and note to change MYSQL user root can access from local to internet(%)\nchar pass&#91;] = \"SQLpassword\";\/\/ Your MYSQL password\n\nWiFiClient client;            \nMySQL_Connection conn((Client *)&amp;client);\n\nvoid setup() {\n  Serial.begin(115200);\n  delay(10);\n  \/\/ We start by connecting to a WiFi network\n  Serial.println();\n  Serial.println();\n  Serial.print(\"Connecting to \");\n  Serial.println(ssid);\n  \n  WiFi.begin(ssid, password);  \n  \/\/try to connect to WIFI \n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n  Serial.println(\"\");\n  Serial.println(\"WiFi connected\");  \n  Serial.println(\"IP address: \");\n  Serial.println(WiFi.localIP());\n  \n  \/\/try to connect to mysql server\n  if (conn.connect(server_addr, 3306, user, pass)) {\n     delay(1000);\n  }\n  else{\n    Serial.println(\"Connection failed.\");\n  }\n  delay(2000);  \n  \/\/insert, change database name and values by string and char&#91;]\n  char INSERT_SQL&#91;] = \"INSERT INTO tempandhumd.datalog (temp,humd) VALUES ('35','60')\";\/\/\u50b3\u5165\u7684\u503c\u56fa\u5b9a\u70ba\u6eab\u5ea6,\u6fd5\u5ea6\u70ba35,60\n  MySQL_Cursor *cur_mem = new MySQL_Cursor(&amp;conn);  \n  cur_mem-&gt;execute(INSERT_SQL);\/\/execute SQL\n  delete cur_mem;\n  conn.close();                  \/\/ close the connection\n  Serial.println(\"Data Saved.\");\n}\n\nvoid loop() {\n\/\/do nothing\n}<\/code><\/pre>\n\n\n\n<p>\u82e5\u4e0a\u50b3\u6210\u529f\uff0c\u5728\u8cc7\u6599\u5eab\u5167\u5c31\u6703\u51fa\u73fe\u525b\u525b\u4e0a\u50b3\u7684\u8cc7\u6599<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583610829-791104813.png?resize=839%2C518&#038;ssl=1\" alt=\"\" width=\"839\" height=\"518\"\/><figcaption class=\"wp-element-caption\">\u7a0b\u5f0f\u4e0a\u50b3\u6210\u529f\u756b\u9762<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583598650-2900477391.png?resize=838%2C324&#038;ssl=1\" alt=\"\" width=\"838\" height=\"324\"\/><figcaption class=\"wp-element-caption\">\u6210\u529f\u5f8c\u8cc7\u6599\u50b3\u8f38\u5230mysql\u8cc7\u6599\u5eab<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htoc-3-dht11\">3.DHT11\u6e2c\u8a66<\/h3>\n\n\n\n<p>\u4f9d\u64da\u300c<a href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/17\/esp32_ch1-6\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u7b2c\u4e5d\u7bc7 ESP32 \u6eab\u6fd5\u5ea6\u986f\u793a\u5668(DHT11+1602 LCD)<\/a>\u300d\u7684\u65b9\u5f0f\uff0c\u5c07DHT11\u8173\u4f4d\u8a0a\u865f\u7684\u8173\u4f4d\u63a5\u5728GPIO 14\u7684\u4f4d\u7f6e\uff08\u9eb5\u5305\u677f\u5de6\u50748\uff09\uff0c\u63a5\u4e0b\u4f86\u7a0b\u5f0f\u6539\u70ba\u6bcf10\u79d2\u8b80\u53d6DHT11\u4e00\u6b21\uff0c\u4e26\u4e0a\u50b3\u8cc7\u6599\u5eab\uff0c\u5b8c\u6210\u4e0a\u50b3\u5f8c\u5c31\u7acb\u5373\u65b7\u7dda\u8cc7\u6599\u5eab\uff0c\u7b49\u5019\u4e0b\u4e00\u500bLoop\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h&gt;\n#include &lt;MySQL_Connection.h&gt;\n#include &lt;MySQL_Cursor.h&gt;\n#include &lt;SimpleDHT.h&gt;\n\nconst char ssid&#91;]     = \"SSID\";\/\/ change to your WIFI SSID\nconst char password&#91;] = \"SSIDPassword\";\/\/ change to your WIFI Password\n\nIPAddress server_addr(192,168,1,17); \/\/ change to you server ip, note its form split by \",\" not \".\"\nint MYSQLPort = 3306; \/\/mysql port default is 3306\nchar user&#91;] = \"root\";\/\/ Your MySQL user login username(default is root),and note to change MYSQL user root can access from local to internet(%)\nchar pass&#91;] = \"SQLpassword\";\/\/ Your MYSQL password\n\nWiFiClient client;\nMySQL_Connection conn((Client *)&amp;client);\n\nint pinDHT11 = 14;\nSimpleDHT11 dht11(pinDHT11);\nvoid setup() {\n  Serial.begin(115200);\n  delay(10);\n  \/\/ We start by connecting to a WiFi network\n  Serial.println();\n  Serial.println();\n  Serial.print(\"Connecting to \");\n  Serial.println(ssid);\n\n  WiFi.begin(ssid, password);\n  \/\/try to connect to WIFI\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n  Serial.println(\"\");\n  Serial.println(\"WiFi connected\");\n  Serial.println(\"IP address: \");\n  Serial.println(WiFi.localIP());\n\n  \/\/try to connect to mysql server\n  if (conn.connect(server_addr, 3306, user, pass)) {\n    delay(1000);\n  }\n  else {\n    Serial.println(\"Connection failed.\");\n  }\n  delay(2000);\n\n}\n\nvoid loop() {\n  \/\/\u8b80\u53d6DHT11\n  byte temperature = 0;\n  byte humidity = 0;\n  int err = SimpleDHTErrSuccess;\n  if ((err = dht11.read(&amp;temperature, &amp;humidity, NULL)) != SimpleDHTErrSuccess) {\n    Serial.print(\"Read DHT11 failed, err=\"); Serial.println(err); delay(1000);\n    return;\n  }\n  Serial.print(\"Sample OK: \");\n  Serial.print((int)temperature); Serial.print(\" *C, \");\n  Serial.print((int)humidity); Serial.println(\" H\");\n\n  \/\/\u5c07\u6eab\u6fd5\u5ea6\u52a0\u5165SQL\u5b57\u4e32\n  String INSERT_SQL = \"INSERT INTO test.loj (t,h) VALUES ('\" + String((int)temperature) + \"','\" + String((int)humidity) + \"')\";\n  MySQL_Cursor *cur_mem = new MySQL_Cursor(&amp;conn);\n  cur_mem-&gt;execute(INSERT_SQL.c_str());\/\/execute SQL\n  delete cur_mem;\n  conn.close();\/\/ close the connection\n  Serial.println(\"Data Saved.\");\n  delay(10000);\n}<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u5e8f\u5217\u8996\u7a97\uff0c\u53ef\u4ee5\u767c\u73fe\u4e0a\u50b3\u6b63\u5e38\uff0c\u67e5\u770b\u8cc7\u6599\u5eab\uff0c\u4e5f\u53ef\u4ee5\u767c\u73fe\u8cc7\u6599\u90fd\u5df2\u7d93\u5b58\u5165\u8cc7\u6599\u5eab\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1583613636-1177100998.png?resize=841%2C644&#038;ssl=1\" alt=\"\" width=\"841\" height=\"644\"\/><figcaption class=\"wp-element-caption\">DHT11\u6210\u529f\u9023\u7dda-\u5e8f\u5217\u57e0\u756b\u9762<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>ESP\u5167\u5efa\u7684WiFi\u4e0a\u7db2\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5c07\u6536\u96c6\u5230\u7684\u8cc7\u6599\u5b58\u5165\u96f2\u7aef\u8cc7\u6599\u5eab\uff0c\u65b9\u4fbf\u7acb\u5373\u67e5\u770b\u5373\u6642\u72c0\u6cc1\uff0c\u800c\u4e14\u6709\u9577\u671f\u7684\u8cc7\u6599\u5f8c\u5c31\u53ef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,29],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-esp32","category-esp32-started"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":8,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":2803,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/511\/revisions\/2803"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}