{"id":6381,"date":"2021-04-09T04:23:00","date_gmt":"2021-04-08T20:23:00","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6381"},"modified":"2021-04-10T04:28:54","modified_gmt":"2021-04-09T20:28:54","slug":"%e4%bd%bf%e7%94%a8-python-%e4%bb%8e-0-%e5%bc%80%e5%8f%91%e5%b1%9e%e4%ba%8e%e4%bd%a0%e7%9a%84%e4%b8%aa%e4%ba%ba%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f-06-%e7%af%87-%ef%bd%9c-%e5%ae%89%e8%a3%85%e5%a5%bd","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6381","title":{"rendered":"\u4f7f\u7528 Python \u4ece 0 \u5f00\u53d1\u5c5e\u4e8e\u4f60\u7684\u4e2a\u4eba\u7ba1\u7406\u7cfb\u7edf 06 \u7bc7 \uff5c \u5b89\u88c5\u597d\u4f60\u7684\u6570\u636e\u5e93 MYSQL\uff0c\u7136\u540e\u7528 flask-sqlalchemy \u914d\u7f6e\u5b83"},"content":{"rendered":"\n<p>\u6211\u4eec\u8981\u5f00\u53d1\u7ba1\u7406\u7cfb\u7edf\uff0c\u7528\u5230\u7684\u662f\u52a8\u6001\u7684\u6570\u636e\uff0c\u6240\u4ee5\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u5e02\u9762\u4e0a\u7684\u6570\u636e\u5e93\u79cd\u7c7b\u633a\u591a\u7684\uff0c\u6709\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u76f8\u5bf9\u6765\u8bf4\uff0c\u6211\u4eec\u6bd4\u8f83\u5e38\u7528\u7684\u8fd8\u662f MYSQL\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u7684\u9879\u76ee\u4f1a\u4f7f\u7528\u5230\u5b83\uff0cFlask \u5982\u4f55\u7ed3\u5408\u6570\u636e\u5e93\u8fdb\u884c\u64cd\u4f5c\u5462\uff1f<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u5b89\u88c5\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u8d81\u73b0\u5728\u5b89\u88c5\u4e00\u6ce2\u3002<\/p>\n\n\n\n<h1>\u5b89\u88c5mysql<\/h1>\n\n\n\n<h2>windows \u5b89\u88c5 mysql<\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u662f windows \u7cfb\u7edf\uff0c\u53ef\u4ee5\u5728\u8fd9\u91cc\u4e0b\u8f7d\u5b89\u88c5\u6839\u636e\u6307\u5f15\u5b89\u88c5\uff1a<a href=\"https:\/\/dev.mysql.com\/downloads\/windows\/\">https:\/\/dev.mysql.com\/downloads\/windows\/<\/a><\/p>\n\n\n\n<h2>Linux \u5b89\u88c5 mysql<\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u662f Linux \u7cfb\u7edf\uff0c\u5b89\u88c5\u65b9\u5f0f\u4e5f\u5f88\u7b80\u5355\uff0c\u8fd9\u91cc\u4ee5 ubuntu \u7cfb\u7edf\u4e3a\u4f8b\uff0c\u5b89\u88c5\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<h2>ubuntu\u5b89\u88c5mysql\u547d\u4ee4<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>sudo apt-get install mysql-server<\/p><\/blockquote>\n\n\n\n<p>\u6309 Y \u786e\u8ba4\u5b89\u88c5<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"726\" height=\"430\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql01.png\" alt=\"\" class=\"wp-image-6382\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql01.png 726w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql01-300x178.png 300w\" sizes=\"(max-width: 726px) 100vw, 726px\" \/><\/figure><\/div>\n\n\n\n<h2>\u914d\u7f6e Mysql \u5bc6\u7801<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>sudo mysql_secure_installation<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"685\" height=\"422\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql02.png\" alt=\"\" class=\"wp-image-6383\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql02.png 685w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql02-300x185.png 300w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><\/figure><\/div>\n\n\n\n<h2>\u68c0\u67e5\u662f\u5426\u8fd0\u884c<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>systemctl status mysql.service<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"723\" height=\"150\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql03.png\" alt=\"\" class=\"wp-image-6384\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql03.png 723w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql03-300x62.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure><\/div>\n\n\n\n<h1>\u4f7f\u7528 mysql<\/h1>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>sudo mysql -uroot -p<\/p><\/blockquote>\n\n\n\n<p>\u8f93\u5165\u5bc6\u7801\u5373\u53ef\u4f7f\u7528\uff1a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"730\" height=\"274\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql04.png\" alt=\"\" class=\"wp-image-6385\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql04.png 730w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql04-300x113.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/figure><\/div>\n\n\n\n<h2>\u914d\u7f6e mysql \u8fdc\u7a0b\u8fde\u63a5<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>GRANT ALL ON *.* TO &#8216;root&#8217;@&#8217;localhost&#8217;;<\/p><\/blockquote>\n\n\n\n<p><code>*.*<\/code> \u4ee3\u8868\u6240\u6709\u6570\u636e\u5e93\uff0c\u5982\u679c\u8981\u8bbe\u7f6e\u5355\u4e2a\u6570\u636e\u5e93\u53ef\u81ea\u884c\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u8bbe\u7f6e\u5b8c\u540e\u66f4\u65b0\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>flush PRIVILEGES;<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"698\" height=\"128\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql05.png\" alt=\"\" class=\"wp-image-6387\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql05.png 698w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/04\/mysql05-300x55.png 300w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/figure><\/div>\n\n\n\n<h2>Mac \u5b89\u88c5 mysql<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528 homwbrew \u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>brew install mysql<\/p><\/blockquote>\n\n\n\n<h2>\u8fd0\u884c mysql<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>mysql.server start<\/p><\/blockquote>\n\n\n\n<h2>\u8bbe\u7f6e root \u5bc6\u7801<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>mysql_secure_installation<\/p><\/blockquote>\n\n\n\n<p>\u5176\u5b83\u64cd\u4f5c\u548c\u4e0a\u8ff0\u7684 Linux \u4f7f\u7528 mysql \u76f8\u540c\u3002<\/p>\n\n\n\n<h1>Flask \u914d\u7f6e SQL<\/h1>\n\n\n\n<p>\u76f8\u4fe1\u4f60\u5df2\u7ecf\u5728\u4f60\u7684\u7535\u8111\u4e2d\u5b89\u88c5\u597d MySQL \u4e86\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u54b1\u4eec\u5c31\u6765\u73a9\u73a9\u5b83\u3002<\/p>\n\n\n\n<p>\u6709\u4e00\u4e2a Flask \u63d2\u4ef6\u53eb\u505a Flask-SQLAlchemy \uff0c\u4f7f\u7528\u5b83\u6211\u4eec\u53ef\u4ee5\u5728\u9879\u76ee\u4f7f\u7528\u5bf9\u8c61\u548c MySQL \u5173\u7cfb\u8fdb\u884c\u6620\u5c04\u3002<\/p>\n\n\n\n<p>\u5148\u5b89\u88c5\u4e00\u6ce2\u5427\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>pipenv install flask-sqlalchemy<\/p><\/blockquote>\n\n\n\n<h2>\u914d\u7f6e\u6587\u4ef6\u7684\u4f7f\u7528<\/h2>\n\n\n\n<p>\u5728\u9879\u76ee\u6587\u4ef6\u4e2d\uff0c\u521b\u5efa<div style=\"text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;\">\u672c\u6587\u9690\u85cf\u5185\u5bb9 <a href=\"https:\/\/vip.fxxkpython.com\/wp-login.php?redirect_to=https%3A%2F%2Fvip.fxxkpython.com%2F%3Fp%3D6381\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u8fd0\u884c\u8d77\u6765\uff08python app.py\uff09\uff0c\u5982\u679c\u6ca1\u62a5\u4ec0\u4e48\u9519\uff0c\u8bf4\u660e\u4f60\u7684\u6570\u636e\u5e93\u8fde\u63a5\u6210\u529f\u3002<\/p>\n\n\n\n<p>OK\uff0c\u4f60\u73b0\u5728\u53ef\u4ee5\u628a MySQL \u5b89\u88c5\u597d\uff0c\u5e76\u5c06 flask-sqlalchemy \u914d\u7f6e\u8d77\u6765\uff0c\u4e0b\u4e00\u7bc7\u6211\u4f1a\u7ed9\u4f60\u4ecb\u7ecd\uff0c\u5982\u4f55\u4f7f\u7528\u5b83\u6765\u521b\u5efa\u6570\u636e\u8868\uff0c\u4ee5\u53ca\u5982\u4f55\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u7684\u64cd\u4f5c\u3002\u4e0b\u56de\u89c1\uff0cpeace\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u8981\u5f00\u53d1\u7ba1\u7406\u7cfb\u7edf\uff0c\u7528\u5230\u7684\u662f\u52a8\u6001\u7684\u6570\u636e\uff0c\u6240\u4ee5\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u5e02\u9762\u4e0a\u7684\u6570\u636e\u5e93\u79cd\u7c7b\u633a\u591a\u7684\uff0c\u6709\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u76f8\u5bf9\u6765\u8bf4\uff0c\u6211\u4eec\u6bd4\u8f83\u5e38\u7528\u7684\u8fd8\u662f MYSQL\uff0c\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u7684\u9879\u76ee\u4f1a\u4f7f\u7528\u5230\u5b83\uff0cFlask \u5982\u4f55\u7ed3\u5408\u6570\u636e\u5e93\u8fdb\u884c\u64cd\u4f5c\u5462\uff1f \u5982\u679c\u4f60\u8fd8\u6ca1\u5b89\u88c5\u6570\u636e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[577,580,581,579,19,576],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6381"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6381"}],"version-history":[{"count":2,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6381\/revisions"}],"predecessor-version":[{"id":6388,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6381\/revisions\/6388"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6384"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}