{"id":35901,"date":"2025-05-07T08:15:50","date_gmt":"2025-05-07T00:15:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35901.html"},"modified":"2025-05-07T08:15:50","modified_gmt":"2025-05-07T00:15:50","slug":"%e5%90%8e%e7%ab%af%e9%83%a8%e7%bd%b2%ef%bc%9aflask-pymysql-mysql%e8%bf%81%e7%a7%bb%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%88%e4%bb%a5linux%e4%b8%ba%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35901.html","title":{"rendered":"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09"},"content":{"rendered":"<h4>1. \u8fc1\u79fbWindows\u4e0a\u7684MySQL\u6570\u636e\u5e93<\/h4>\n<h5>\u2460 \u5bfc\u51fa\u6570\u636e\uff08Windows\u547d\u4ee4\u884c\uff09<\/h5>\n<p># \u8fdb\u5165MySQL\u5b89\u88c5\u76ee\u5f55\u7684bin\u6587\u4ef6\u5939<br \/>\ncd C:\\\\Program Files\\\\MySQL\\\\MySQL Server 8.0\\\\bin<\/p>\n<p># \u5bfc\u51fa\u6570\u636e\u5e93\uff08\u542b\u7ed3\u6784\u548c\u6570\u636e\uff09<br \/>\nmysqldump -u root -p your_db_name &gt; backup.sql<\/p>\n<h5>\u2461 \u5728Linux\u670d\u52a1\u5668\u5b89\u88c5MySQL<\/h5>\n<p><span class=\"token comment\"># Ubuntu\u793a\u4f8b<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> mysql-server<br \/>\n<span class=\"token function\">sudo<\/span> systemctl start mysql<br \/>\n<span class=\"token function\">sudo<\/span> mysql_secure_installation  <span class=\"token comment\"># \u521d\u59cb\u5316\u5b89\u5168\u8bbe\u7f6e<\/span><\/p>\n<h5>\u2462 \u5bfc\u5165\u6570\u636e\uff08Linux\u7ec8\u7aef\uff09<\/h5>\n<p>mysql -u root -p your_db_name <span class=\"token operator\">&lt;<\/span> backup.sql<\/p>\n<h4>2. \u90e8\u7f72Flask\u540e\u7aef<\/h4>\n<h5>\u2460 \u51c6\u5907\u9879\u76ee\u6587\u4ef6\uff08Windows\u64cd\u4f5c\uff09<\/h5>\n<ul>\n<li>\u5bfc\u51fa\u4f9d\u8d56\uff1a<\/li>\n<\/ul>\n<p>pip freeze &gt; requirements.txt<\/p>\n<p>\u7531\u4e8e\u4f7f\u7528\u4e86pymysql\uff0crequirements.txt\u6587\u4ef6\u4e2d\u5e94\u8be5\u5305\u542bpymysql\u53ca\u5176\u7248\u672c\u4fe1\u606f\u3002<\/p>\n<ul>\n<li>\u786e\u4fdd\u4ee3\u7801\u4e2d\u6570\u636e\u5e93\u8fde\u63a5\u6539\u4e3a\u670d\u52a1\u5668IP\uff0c\u5e76\u4e14\u4f7f\u7528pymysql\u8fde\u63a5\uff1a<\/li>\n<\/ul>\n<p><span class=\"token keyword\">from<\/span> flask_sqlalchemy <span class=\"token keyword\">import<\/span> SQLAlchemy<br \/>\n<span class=\"token keyword\">from<\/span> flask <span class=\"token keyword\">import<\/span> Flask<\/p>\n<p>app <span class=\"token operator\">=<\/span> Flask<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb811\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u6570\u636e\u5e93\u8fc1\u79fb\uff1aWindows\u5bfc\u51faMySQL\u6570\u636e\u2192\u670d\u52a1\u5668\u5bfc\u5165\uff08Linux\/Windows\u5747\u53ef\uff09\u3002\u540e\u7aef\u90e8\u7f72Linux\uff1aGunicorn+Nginx\uff08\u9ad8\u6027\u80fd\uff0c\u63a8\u8350\uff09\u3002Windows\uff1aIIS+FastCGI\uff08\u517c\u5bb9\u65e7\u67b6\u6784\uff09\u3002\u524d\u7aef\u90e8\u7f72\uff1aMac\u6253\u5305Vue\u2192\u670d\u52a1\u5668\u6258\u7ba1\u9759\u6001\u6587\u4ef6\uff08Nginx\/IIS\uff09\u3002\u4ea4\u4e92\u914d\u7f6e\uff1a\u901a\u8fc7Nginx\u53cd\u5411\u4ee3\u7406\u7edf\u4e00\u8def\u5f84\uff0c\u5f7b\u5e95\u89e3\u51b3\u8de8\u57df\u95ee\u9898\u3002\u65e0\u8bba\u524d\u540e\u7aef\u5f00\u53d1\u73af\u5883\u5982\u4f55\uff0c\u670d\u52a1\u5668\u7aef\u901a\u8fc7\u6807\u51c6\u5316\u90e8\u7f72\u6d41\u7a0b\uff08\u4f9d\u8d56\u6e05\u5355\u3001\u53cd\u5411\u4ee3\u7406\u3001\u8de8\u57df\u5904\u7406\uff09\uff0c\u90fd\u80fd\u5b9e\u73b0\u7a33\u5b9a\u4ea4\u4e92\u3002_flask linux mysql\u6570\u636e\u5e93<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[153,330,114,81,149,87],"topic":[],"class_list":["post-35901","post","type-post","status-publish","format-standard","hentry","category-server","tag-flask","tag-macos","tag-mysql","tag-python","tag-windows","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35901.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb811\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u6570\u636e\u5e93\u8fc1\u79fb\uff1aWindows\u5bfc\u51faMySQL\u6570\u636e\u2192\u670d\u52a1\u5668\u5bfc\u5165\uff08Linux\/Windows\u5747\u53ef\uff09\u3002\u540e\u7aef\u90e8\u7f72Linux\uff1aGunicorn+Nginx\uff08\u9ad8\u6027\u80fd\uff0c\u63a8\u8350\uff09\u3002Windows\uff1aIIS+FastCGI\uff08\u517c\u5bb9\u65e7\u67b6\u6784\uff09\u3002\u524d\u7aef\u90e8\u7f72\uff1aMac\u6253\u5305Vue\u2192\u670d\u52a1\u5668\u6258\u7ba1\u9759\u6001\u6587\u4ef6\uff08Nginx\/IIS\uff09\u3002\u4ea4\u4e92\u914d\u7f6e\uff1a\u901a\u8fc7Nginx\u53cd\u5411\u4ee3\u7406\u7edf\u4e00\u8def\u5f84\uff0c\u5f7b\u5e95\u89e3\u51b3\u8de8\u57df\u95ee\u9898\u3002\u65e0\u8bba\u524d\u540e\u7aef\u5f00\u53d1\u73af\u5883\u5982\u4f55\uff0c\u670d\u52a1\u5668\u7aef\u901a\u8fc7\u6807\u51c6\u5316\u90e8\u7f72\u6d41\u7a0b\uff08\u4f9d\u8d56\u6e05\u5355\u3001\u53cd\u5411\u4ee3\u7406\u3001\u8de8\u57df\u5904\u7406\uff09\uff0c\u90fd\u80fd\u5b9e\u73b0\u7a33\u5b9a\u4ea4\u4e92\u3002_flask linux mysql\u6570\u636e\u5e93\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35901.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-07T00:15:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35901.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35901.html\",\"name\":\"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-07T00:15:50+00:00\",\"dateModified\":\"2025-05-07T00:15:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35901.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35901.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35901.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35901.html","og_locale":"zh_CN","og_type":"article","og_title":"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb811\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u6570\u636e\u5e93\u8fc1\u79fb\uff1aWindows\u5bfc\u51faMySQL\u6570\u636e\u2192\u670d\u52a1\u5668\u5bfc\u5165\uff08Linux\/Windows\u5747\u53ef\uff09\u3002\u540e\u7aef\u90e8\u7f72Linux\uff1aGunicorn+Nginx\uff08\u9ad8\u6027\u80fd\uff0c\u63a8\u8350\uff09\u3002Windows\uff1aIIS+FastCGI\uff08\u517c\u5bb9\u65e7\u67b6\u6784\uff09\u3002\u524d\u7aef\u90e8\u7f72\uff1aMac\u6253\u5305Vue\u2192\u670d\u52a1\u5668\u6258\u7ba1\u9759\u6001\u6587\u4ef6\uff08Nginx\/IIS\uff09\u3002\u4ea4\u4e92\u914d\u7f6e\uff1a\u901a\u8fc7Nginx\u53cd\u5411\u4ee3\u7406\u7edf\u4e00\u8def\u5f84\uff0c\u5f7b\u5e95\u89e3\u51b3\u8de8\u57df\u95ee\u9898\u3002\u65e0\u8bba\u524d\u540e\u7aef\u5f00\u53d1\u73af\u5883\u5982\u4f55\uff0c\u670d\u52a1\u5668\u7aef\u901a\u8fc7\u6807\u51c6\u5316\u90e8\u7f72\u6d41\u7a0b\uff08\u4f9d\u8d56\u6e05\u5355\u3001\u53cd\u5411\u4ee3\u7406\u3001\u8de8\u57df\u5904\u7406\uff09\uff0c\u90fd\u80fd\u5b9e\u73b0\u7a33\u5b9a\u4ea4\u4e92\u3002_flask linux mysql\u6570\u636e\u5e93","og_url":"https:\/\/www.wsisp.com\/helps\/35901.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-07T00:15:50+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35901.html","url":"https:\/\/www.wsisp.com\/helps\/35901.html","name":"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-07T00:15:50+00:00","dateModified":"2025-05-07T00:15:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35901.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35901.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35901.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u540e\u7aef\u90e8\u7f72\uff1aFlask + pymysql + MySQL\u8fc1\u79fb\u5230\u670d\u52a1\u5668\uff08\u4ee5Linux\u4e3a\u4f8b\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=35901"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35901\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35901"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}