{"id":53,"date":"2015-12-25T09:49:13","date_gmt":"2015-12-25T01:49:13","guid":{"rendered":"http:\/\/www.shenmdyw.com\/?p=53"},"modified":"2015-12-25T10:45:02","modified_gmt":"2015-12-25T02:45:02","slug":"python-2-mysql","status":"publish","type":"post","link":"http:\/\/www.shenmdyw.com\/index.php\/2015\/12\/25\/python-2-mysql\/","title":{"rendered":"python3.4  \u8fde\u63a5mysql pymysql\u8fde\u63a5mysql\u6570\u636e\u5e93"},"content":{"rendered":"<p>\u5728<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/python\/\" target=\"_blank\">python<\/a>3.4\u4e2d\u4f7f\u7528\u539f\u6765python2.7\u7684<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/mysql\/\" target=\"_blank\">mysql<\/a>db\u5df2\u4e0d\u80fd\u8fde\u63a5mysql<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/db\/\" target=\"_blank\">\u6570\u636e\u5e93<\/a>\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528pymysql\uff0c\u6765\u5b8c\u6210\u8fde\u63a5mysql\u7684\u91cd\u4efb\u3002<\/p>\n<p>\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<p>\u5e8f\u53f7\u00a0\u63cf\u8ff0<br \/>\n1\u00a0\u53bbgithub\u4e0a\u4e0b\u8f7dpymysql\u7684\u5b89\u88c5\u5305pymysql https:\/\/github.com\/PyMySQL\/PyMySQL<br \/>\n2\u00a0\u89e3\u538b\u5230\u67d0\u4e2a\u76d8\u7b26\u4e0b<br \/>\n3\u00a0\u6253\u5f00cmd\u7a97\u53e3\uff08win\u73af\u5883\u4e0b\uff09\uff0c\u8fdb\u5165pymysql\u7684\u6839\u76ee\u5f55\u4e0b\u6267\u884c<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/start\/cmd\/\" target=\"_blank\">\u547d\u4ee4<\/a>\uff0cpython setup.py install<br \/>\n4\u00a0\u5728<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/dev\/\" target=\"_blank\">\u7a0b\u5e8f<\/a>\u91cc\uff0c\u5bfc\u5165pymysql<br \/>\n5\u00a0\u5f00\u59cb\u8fde\u63a5\u6570\u636e\u5e93<\/p>\n<p><!--more--><\/p>\n<p>\u6570\u636e\u5e93\u64cd\u4f5c\u7684API\u6587\u6863\u8fde\u63a5:http:\/\/legacy.python.org\/dev\/peps\/pep-0249\/<\/p>\n<p>\u4f8b\u5b50\uff1a<br \/>\n\u4ee3\u7801\u793a\u4f8b:<br \/>\n__author__ = &#8216;qindongliang&#8217;<br \/>\n#\u5bfc\u5165pymysql\u7684\u5305<br \/>\nimport pymysql<br \/>\ntry:<br \/>\n#\u83b7\u53d6\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u6ce8\u610f\u5982\u679c\u662fUTF-8\u7c7b\u578b\u7684\uff0c\u9700\u8981\u5236\u5b9a\u6570\u636e\u5e93<br \/>\nconn=pymysql.connect(host=&#8217;lo<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/start\/cmd\/9060.html\" target=\"_blank\">cal<\/a>host&#8217;,user=&#8217;root&#8217;,passwd=&#8217;qin&#8217;,db=&#8217;person&#8217;,port=3306,charset=&#8217;utf8&#8242;)<br \/>\ncur=conn.cursor()#\u83b7\u53d6\u4e00\u4e2a\u6e38\u6807<br \/>\ncur.exe<a class=\"keylink\" href=\"http:\/\/www.ahlinux.com\/start\/cmd\/2818.html\" target=\"_blank\">cut<\/a>e(&#8216;select * from person&#8217;)<br \/>\ndata=cur.fetchall()<br \/>\nfor d in data :<br \/>\n#\u6ce8\u610fint\u7c7b\u578b\u9700\u8981\u4f7f\u7528str\u51fd\u6570\u8f6c\u4e49<br \/>\nprint(&#8220;ID: &#8220;+str(d[0])+&#8217;\u00a0 \u540d\u5b57\uff1a &#8216;+d[1]+&#8221;\u00a0 \u6027\u522b\uff1a &#8220;+d[2])<\/p>\n<p>cur.close()#\u5173\u95ed\u6e38\u6807<br \/>\nconn.close()#\u91ca\u653e\u6570\u636e\u5e93\u8d44\u6e90<br \/>\nexcept\u00a0 Exception :print(&#8220;\u53d1\u751f\u5f02\u5e38&#8221;)<\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<br \/>\nD:\\python\\python.exe D:\/pythonide\/pythonprojectworkspace\/python\/mysql.py<br \/>\nID: 1\u00a0 \u540d\u5b57\uff1a \u79e6\u5929\u00a0 \u6027\u522b\uff1a \u7537<br \/>\nID: 2\u00a0 \u540d\u5b57\uff1a \u738b\u6676\u00a0 \u6027\u522b\uff1a \u5973<\/p>\n<p>Process finished with exit code 0<\/p>\n<ul class=\"l_text clear_div\">\n<li>\u672c\u6587\u6765\u81ea\uff1a<a href=\"http:\/\/www.ahlinux.com\/\">\u7231\u597dLinux\u6280\u672f\u7f51<\/a><\/li>\n<li>\u672c\u6587\u94fe\u63a5\uff1a<a href=\"http:\/\/www.ahlinux.com\/python\/13641.html\">http:\/\/www.ahlinux.com\/python\/13641.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728python3.4\u4e2d\u4f7f\u7528\u539f\u6765python2.7\u7684mysqldb\u5df2\u4e0d\u80fd\u8fde\u63a5mysql\u6570\u636e\u5e93\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528pymy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[37,38],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-mysql","tag-python-","clear"],"_links":{"self":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":2,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":55,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions\/55"}],"wp:attachment":[{"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.shenmdyw.com\/index.php\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}