{"id":26341,"date":"2024-11-24T09:08:13","date_gmt":"2024-11-24T01:08:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26341\/"},"modified":"2024-11-24T09:08:13","modified_gmt":"2024-11-24T01:08:13","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26341\/","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><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173089044433904.jpg\" class=\"aligncenter\" title=\"Python3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"Python3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>3 \u62a5\u9519\uff1a\u63d2\u5165\u6570\u636e\u5e93\u5931\u8d25<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 python3 \u63d2\u5165  \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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fPython3 \u8fde\u63a5 MySQL \u6570\u636e\u5e93\u63d2\u5165\u5931\u8d25\uff1a\u5982\u4f55\u89e3\u51b3\u4e8b\u52a1\u56de\u6eda\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3 \u62a5\u9519\uff1a\u63d2\u5165\u6570\u636e\u5e93\u5931\u8d25 \u5728\u4f7f\u7528 python3 \u63d2\u5165 \u6570\u636e\u5e93\u65f6\uff0c\u9047\u5230\u5982\u4e0b\u7684\u9519\u8bef\u63d0\u793a\uff1a &lt;p&gt;\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&lt;\/p&gt; \u767b\u5f55\u540e\u590d\u5236 \u89e3\u51b3\u65b9\u6848\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \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 import requests import time import json import pymysql mydb = pymysql.connect( host=&#8221;92.68.40.12&#8243;, port=3306, user=&#8221;root&#8221;, password=&#8221;iss_root&#8221;, database=&#8221;dynamic_premium_db&#8221; ) mycursor = mydb.cursor() def excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time): sql = &#8220;INSERT INTO over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)VALUES(&#8216;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;)&#8221; % ( stratagy_id, city_id, app_name, total_price, over_flow_price, date_time) try: mycursor.execute(sql) print(&#8216;\u63d2\u5165\u6210\u529f&#8217;) except [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26341","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26341"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26341\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}