{"id":200804,"date":"2025-05-06T11:43:09","date_gmt":"2025-05-06T03:43:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200804\/"},"modified":"2025-05-06T11:43:09","modified_gmt":"2025-05-06T03:43:09","slug":"python3-%e8%bf%9e%e6%8e%a5-mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8f%92%e5%85%a5%e5%a4%b1%e8%b4%a5%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e4%ba%8b%e5%8a%a1%e5%9b%9e%e6%bb%9a%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200804\/","title":{"rendered":"Python3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Python3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241115\/17316515276736e7c74fcae.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python3 \u62a5\u9519\uff1a\u63d2\u5165\u6570\u636e\u5e93\u5931\u8d25<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 python3 \u63d2\u5165 mysql \u6570\u636e\u5e93\u65f6\uff0c\u9047\u5230\u5982\u4e0b\u7684\u9519\u8bef\u63d0\u793a\uff1a<\/p>\n<pre>&lt;p&gt;\u5904\u7406\u4e2d..................&lt;\/p&gt;<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u7ecf\u67e5\u8bc1\uff0c\u5f15\u53d1\u6b64\u9519\u8bef\u7684\u539f\u56e0\u662f\u8bd5\u56fe\u8fdb\u884c\u6570\u636e\u5e93\u4e8b\u52a1\u56de\u6eda\u64cd\u4f5c\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e76\u4e0d\u9700\u8981\u3002\u4ee5\u4e0b\u4e3a\u4fee\u6539\u540e\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>import requests\nimport time\nimport json\nimport pymysql\n\nmydb = pymysql.connect(\n    host=\"92.68.40.12\", port=3306,\n    user=\"root\",\n    password=\"iss_root\",\n    database=\"dynamic_premium_db\"\n)\nmycursor = mydb.cursor()\n\ndef excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time):\n    sql = \"INSERT INTO over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)VALUES('%s','%s','%s','%s','%s','%s')\" % (\n        stratagy_id, city_id, app_name, total_price, over_flow_price, date_time)\n    try:\n        mycursor.execute(sql)\n        print('\u63d2\u5165\u6210\u529f')\n    except Exception as e:\n        print('err: ' + sql)\n        print(e)<\/pre>\n<p>\u5728\u6b64\u4fee\u6539\u4e2d\uff0c\u6211\u4eec\u79fb\u9664\u4e86\u4e8b\u52a1\u5904\u7406\u4ee3\u7801\uff0c\u8fd9\u6837\u5c31\u884c\u4e86\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPython3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Python3 \u8fde\u63a5 MySQL&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200804","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200804"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200804\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}