{"id":1013,"date":"2021-10-19T15:56:16","date_gmt":"2021-10-19T07:56:16","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=1013"},"modified":"2022-05-16T18:02:39","modified_gmt":"2022-05-16T10:02:39","slug":"tdengine","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1013","title":{"rendered":"TDengine\u5b89\u88c5,python\u5ba2\u6237\u7aef\u6d4b\u8bd5,\u63a5\u5165DBeaver"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u7b80\u4ecb<\/h2>\n\n\n\n<p>\u6700\u8fd1\u5728\u770bTDengine\u6570\u636e\u5e93\uff0c\u601d\u8003\u5982\u4f55\u548c\u6211\u4eec\u7684\u8fb9\u7f18\u96c6\u7fa4\u7ed3\u5408\u5728\u4e00\u8d77\u4f7f\u7528\uff0c\u672c\u6587\u7ed3\u6784\u662f\uff1a<\/p>\n\n\n\n<p>\u670d\u52a1\u7aef\uff1aubuntu18\u7cfb\u7edf\uff0c\u901a\u8fc7deb\u6587\u4ef6\u5b89\u88c5TDengine\u6570\u636e\u5e93\uff0c\u4e3b\u673aIP 192.168.0.13,\u4f7f\u7528\u9ed8\u8ba4\u7528\u6237\u540d\u5bc6\u7801<\/p>\n\n\n\n<p>\u5ba2\u6237\u7aef\uff1a\u5bb9\u5668\u8fd0\u884c,python\u5ba2\u6237\u7aef\uff0c\u53ef\u4ee5\u8fd0\u884c\u5728\u53e6\u5916\u4e00\u53f0\u673a\u5668\u6216\u8005K8S\u96c6\u7fa4\u91cc<\/p>\n\n\n\n<p>\u56fe\u5f62\u5316\u5de5\u5177\uff1a\u4f7f\u7528Dbeaver\u6dfb\u52a0jdbc\u9a71\u52a8\uff0c\u5728\u56fe\u5f62\u5316\u5de5\u5177\u91cc\u4f7f\u7528TDengine<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u7aefTDengine\u5b89\u88c5<\/h2>\n\n\n\n<p>\u6839\u636e\u6587\u6863\u63a8\u8350\uff0c\u76ee\u524d\u652f\u6301linux\u88f8\u673a\u5b89\u88c5\uff0c\u4e0d\u5efa\u8baedocker\u5b89\u88c5\uff0c\u6240\u4ee5\u6211\u4eec\u8fd9\u91cc\u88f8\u673a\u5b89\u88c5<\/p>\n\n\n\n<p>1.\u901a\u8fc7\u8fd9\u4e2a<a href=\"https:\/\/www.taosdata.com\/assets-download\/TDengine-server-2.2.0.5-Linux-x64.deb\">https:\/\/www.taosdata.com\/assets-download\/TDengine-server-2.2.0.5-Linux-x64.deb<\/a>\u94fe\u63a5\u4e0b\u8f7d\u5b89\u88c5\u6587\u4ef6<\/p>\n\n\n\n<p>2.\u653e\u7f6e\u6b64\u6587\u4ef6\u5230192.168.0.13\u670d\u52a1\u5668\u4e0a\uff0c\u901a\u8fc7\u547d\u4ee4sudo dpkg -i TDengine-server-2.2.0.5-Linux-x64.deb \u5b89\u88c5<\/p>\n\n\n\n<p>3.\u901a\u8fc7\u547d\u4ee4\u542f\u52a8TDengine\u6570\u636e\u5e93sudo systemctl start taosd<\/p>\n\n\n\n<p>4.\u53c2\u8003<a href=\"https:\/\/www.taosdata.com\/cn\/getting-started\/#Quick%20Start\">https:\/\/www.taosdata.com\/cn\/getting-started\/#Quick%20Start<\/a>\u4e0a\u7684\u547d\u4ee4\u53ef\u4ee5\u53bb\u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\u6d4b\u8bd5<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"TDengine\u5b89\u88c5\u548c\u6d4b\u8bd5-\u5ba2\u6237\u7aef\">python\u5ba2\u6237\u7aef\u5bb9\u5668<\/h2>\n\n\n\n<p>\u4ee5python\u505a\u4e00\u4e2adocker\u5bb9\u5668\u4e3a\u4f8b\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u5f88\u5947\u8469\u7684\u5730\u65b9\uff0c\u6bcf\u4e00\u79cdTDengine\u7684\u8fde\u63a5\u65b9\u5f0f\u90fd\u5fc5\u987b\u8981\u8bbe\u7f6e\u4e00\u4e2ataos.cfg\u7684\u8def\u5f84\uff0c\u548c\u5b89\u88c5\u4e00\u4e2a\u72ec\u7acb\u7684\u5ba2\u6237\u7aef\u7a0b\u5e8f<\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2aDockerfile\u548c\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6sub.py \uff0c\u4e00\u4e2arequirements.txt\u6587\u4ef6\uff0c\u5982\u679c\u4e0d\u7528faker\u5e93\uff0crequirements.txt\u6587\u4ef6\u4e5f\u4e0d\u9700\u8981<\/p>\n\n\n\n<p>Dockerfile\u5185\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM python:3.9.7\nADD . .\nRUN wget https:\/\/www.taosdata.com\/assets-download\/TDengine-client-2.2.0.5-Linux-x64.tar.gz\nRUN tar -xzf TDengine-client-2.2.0.5-Linux-x64.tar.gz\nWORKDIR \/TDengine-client-2.2.0.5\nRUN .\/install_client.sh\nWORKDIR \/\nRUN git clone --depth 1 https:\/\/github.com\/taosdata\/TDengine.git\nRUN pip install -r requirements.txt  -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nRUN pip install .\/TDengine\/src\/connector\/python -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple\nCMD &#91;\"python\",\"test.py\"]<\/code><\/pre>\n\n\n\n<p>\u6d4b\u8bd5\u4e3b\u6587\u4ef6test.py<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\n \nimport taos\nfrom faker import Faker\n \nfake = Faker()\nprint()\nconn = taos.connect(host=\"192.168.0.13\", user=\"root\", password=\"taosdata\", config=\"C:\\TDengine\\cfg\")\nc1 = conn.cursor()\nimport datetime\n \n# \u521b\u5efa\u6570\u636e\u5e93\n# c1.execute('create database db')\nc1.execute('use db')\nprint(\"\u5f00\u59cb\u65f6\u95f4\")\nprint(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))\n \n# # \u5efa\u8868\n# c1.execute('create table tb (ts timestamp, temperature int, humidity float)')\n# # \u63d2\u5165\u6570\u636e\nstart_time = datetime.datetime(2018, 11, 1)\n# affected_rows = c1.execute(\"insert into tb_ts_kv_t values (\\'%s\\', 'DEVICE', '1eb3c1d1d5db250860b6553ce011990', 'DCT', '1623200', True, '123', '456', 3.0)\" %start_time)\n# \u6279\u91cf\u63d2\u5165\u6570\u636e\ntime_interval = datetime.timedelta(seconds=1)\nsqlcmd = &#91;'insert into tb_ts_kv_t values']\nfor irow in range(1, 1000):\n    sqlcmd = &#91;'insert into tb_ts_kv_t values']\n    start_time += time_interval\n    sqlcmd.append(\"('\" + str(start_time) + \"', 'DEVICE', '\"+fake.company()+\"', '\"+fake.name()+\"', '\" + str(\n        irow) + \"', True, '\"+fake.word()+\"', '456', \" + str(irow * 1.2) + \")\")\n    exestring = ' '.join(sqlcmd)\n    # sqlcmd.append('(\\'%s\\', %d, %f)' %(start_time, irow, irow*1.2))\n    affected_rows = c1.execute(exestring)\nprint(\"\u7ed3\u675f\u65f6\u95f4\")\nprint(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))\n \nc1.execute('select * from tb_ts_kv_t')\nfor data in c1:\n    print(\"ts=%s, temperature=%d, humidity=%f\" %(data&#91;0], data&#91;4],data&#91;-1]))<\/code><\/pre>\n\n\n\n<p>requirements.txt\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Faker==9.3.1\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u63a5\u5165\u56fe\u5f62\u5316\u5de5\u5177DBeaver<\/h2>\n\n\n\n<p>1.\u70b9\u51fb\u3010\u6570\u636e\u5e93\u3011-&gt;\u3010\u9a71\u52a8\u7ba1\u7406\u5668\u3011\uff0c\u70b9\u51fb\u3010\u65b0\u5efa\u3011<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"271\" height=\"300\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/image2021-10-19_15-0-36.png\" alt=\"\" class=\"wp-image-1016\"\/><\/figure>\n\n\n\n<p>2,\u8fdb\u884c\u5982\u4e0b\u8bbe\u7f6e\uff0c\u8f93\u5165\u5982\u4e0b\u53c2\u6570<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>key<\/th><th>value<\/th><\/tr><tr><td>\u9a71\u52a8\u540d\u79f0<\/td><td>Tdengine<\/td><\/tr><tr><td>\u9a71\u52a8\u7c7b\u578b<\/td><td>Generic<\/td><\/tr><tr><td>\u7c7b\u540d<\/td><td>com.taosdata.jdbc.TSDBDriver<\/td><\/tr><tr><td>\u9ed8\u8ba4\u7aef\u53e3<\/td><td>6030<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"688\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-2.png\" alt=\"\" class=\"wp-image-1017\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-2.png 485w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-2-211x300.png 211w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/figure>\n\n\n\n<p>3.\u70b9\u51fb\u6dfb\u52a0\u3010\u5de5\u4ef6\u3011\uff0c\u8f93\u5165\u53c2\u6570\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>key<\/th><th>value<\/th><\/tr><tr><td>Group ID<\/td><td>com.taosdata.jdbc<\/td><\/tr><tr><td>taos-jdbcdriver<\/td><td>taos-jdbcdriver<\/td><\/tr><tr><td>\u7248\u672c<\/td><td>RELEASE<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"301\" height=\"271\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-3.png\" alt=\"\" class=\"wp-image-1018\"\/><\/figure>\n\n\n\n<p>4.\u70b9\u51fb\u3010\u9a71\u52a8\u7c7b\u3011\u65c1\u8fb9\u7684\u3010\u627e\u5230\u7c7b\u3011\u6309\u94ae\uff0c\u9009\u62e9\u3010com.taosdata.jdbc.TSDBDriver\u3011\uff0c\u70b9\u51fb\u3010\u786e\u5b9a\u3011<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"360\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-6.png\" alt=\"\" class=\"wp-image-1019\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-6.png 496w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-6-300x218.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/figure>\n\n\n\n<p>5.\u65b0\u5efaTDengine\u8fde\u63a5\uff0c\u53c2\u6570\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>key<\/th><th>value<\/th><\/tr><tr><td>JDBC URL<\/td><td>jdbc:<a href=\"TAOS:\/\/192.168.0.13\/db\">TAOS:\/\/192.168.0.13\/db<\/a><\/td><\/tr><tr><td>\u7528\u6237\u540d<\/td><td>root<\/td><\/tr><tr><td>\u5bc6\u7801<\/td><td>taosdata<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"660\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-7.png\" alt=\"\" class=\"wp-image-1020\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-7.png 725w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2021\/10\/Image-7-300x273.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u6700\u8fd1\u5728\u770bTDengine\u6570\u636e\u5e93\uff0c\u601d\u8003\u5982\u4f55\u548c\u6211\u4eec\u7684\u8fb9\u7f18\u96c6\u7fa4\u7ed3\u5408\u5728\u4e00\u8d77\u4f7f\u7528\uff0c\u672c\u6587\u7ed3\u6784\u662f\uff1a \u670d\u52a1\u7aef\uff1aubunt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":3,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1022,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/1022"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}