{"id":18975,"date":"2025-04-19T01:22:09","date_gmt":"2025-04-18T17:22:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/18975.html"},"modified":"2025-04-19T01:22:09","modified_gmt":"2025-04-18T17:22:09","slug":"%e9%98%bf%e9%87%8c%e4%ba%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%89%e8%a3%85mysql%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/18975.html","title":{"rendered":"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u63d0\u793a&#xff1a;\u672c\u6587\u7ae0\u4e3b\u8981\u8bb0\u5f55\u4e86\u963f\u91cc\u4e91\u4e91\u670d\u52a1\u7684MySQL\u5b89\u88c5<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u5b89\u88c5MySQL<\/li>\n<li>\u589e\u52a0\u6570\u636e\u5e93\u6301\u6709\u7528\u6237<\/li>\n<li>\u521b\u5efa\u6570\u636e\u5e93\u5e76\u589e\u52a0\u8868<\/li>\n<li>\u6d4b\u8bd5\u6570\u636e\u5e93\u8fde\u63a5<\/li>\n<li>\u603b\u7ed3<\/li>\n<\/ul>\n<hr \/>\n<h2>\u5b89\u88c5MySQL<\/h2>\n<p>\u5728Ubuntu\u4e0a\u5b89\u88c5MySQL\u6570\u636e\u5e93\u7684\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\u66f4\u65b0\u5305\u7d22\u5f15&#xff1a; \u6253\u5f00\u7ec8\u7aef&#xff0c;\u9996\u5148\u66f4\u65b0\u60a8\u7684\u5305\u7d22\u5f15&#xff1a;<\/li>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/p>\n<li>\u5b89\u88c5MySQL&#xff1a; \u5b89\u88c5MySQL\u670d\u52a1\u5668&#xff1a;<\/li>\n<p><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> mysql-server<\/p>\n<p>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d&#xff0c;\u7cfb\u7edf\u4f1a\u63d0\u793a\u60a8\u8bbe\u7f6eroot\u7528\u6237\u7684\u5bc6\u7801&#xff0c;\u8bf7\u786e\u4fdd\u8bb0\u4e0b\u8fd9\u4e2a\u5bc6\u7801&#xff0c;\u56e0\u4e3a\u60a8\u4e4b\u540e\u4f1a\u9700\u8981\u5b83\u6765\u7ba1\u7406\u6570\u636e\u5e93\u3002<\/p>\n<li>\u68c0\u67e5MySQL\u670d\u52a1\u72b6\u6001&#xff1a; \u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u60a8\u53ef\u4ee5\u68c0\u67e5MySQL\u670d\u52a1\u7684\u72b6\u6001&#xff1a;<\/li>\n<p><span class=\"token function\">sudo<\/span> systemctl status mysql<\/p>\n<p>\u5982\u679c\u670d\u52a1\u6b63\u5728\u8fd0\u884c&#xff0c;\u60a8\u5c06\u770b\u5230active (running)\u72b6\u6001\u3002<\/p>\n<li>\u5b89\u5168\u914d\u7f6e&#xff1a; \u8fd0\u884c\u5b89\u5168\u811a\u672c\u4ee5\u589e\u5f3aMySQL\u5b89\u88c5\u7684\u5b89\u5168\u6027&#xff1a;<\/li>\n<p><span class=\"token function\">sudo<\/span> mysql_secure_installation<\/p>\n<p>\u8fd9\u4e2a\u811a\u672c\u4f1a\u5f15\u5bfc\u60a8\u5b8c\u6210\u51e0\u4e2a\u6b65\u9aa4&#xff0c;\u5305\u62ec\u8bbe\u7f6eroot\u5bc6\u7801&#xff08;\u5982\u679c\u60a8\u5728\u5b89\u88c5\u65f6\u6ca1\u6709\u8bbe\u7f6e&#xff09;&#xff0c;\u79fb\u9664\u533f\u540d\u7528 \u6237&#xff0c;\u7981\u6b62root\u7528\u6237\u8fdc\u7a0b\u767b\u5f55&#xff0c;\u79fb\u9664\u6d4b\u8bd5\u6570\u636e\u5e93&#xff0c;\u4ee5\u53ca\u91cd\u65b0\u52a0\u8f7d\u6743\u9650\u8868\u3002 \u8fd0\u884cmysql_secure_installation\u4f1a\u6267\u884c\u4ee5\u4e0b\u51e0\u4e2a\u8bbe\u7f6e&#xff1a;<\/p>\n<li>\u4e3aroot\u7528\u6237\u8bbe\u7f6e\u5bc6\u7801&#xff08;\u4e00\u822c\u9700\u8981\u8bbe\u7f6e&#xff09;<\/li>\n<li>\u5220\u9664\u533f\u540d\u8d26\u53f7&#xff08;\u4e0d\u9700\u8981\u533f\u540d\u8d26\u53f7\u5c31\u5220\u4e86&#xff09;<\/li>\n<li>\u53d6\u6d88root\u7528\u6237\u8fdc\u7a0b\u767b\u5f55&#xff08;\u4e0d\u9700\u8981\u8fdc\u7a0b\u767b\u9646\u5c31\u7981\u7528&#xff09;<\/li>\n<li>\u5220\u9664test\u5e93\u548c\u5bf9test\u5e93\u7684\u8bbf\u95ee\u6743\u9650&#xff08;\u53ef\u4ee5\u5728\u6d4b\u8bd5\u4e4b\u540e\u5220\u9664&#xff0c;\u6211\u662f\u76f4\u63a5\u5220\u9664\u7684&#xff09;<\/li>\n<li>\u5237\u65b0\u6388\u6743\u8868\u4f7f\u4fee\u6539\u751f\u6548&#xff08;\u8fd9\u4e2a\u662f\u9700\u8981\u540c\u610f\u7684&#xff0c;\u5e94\u8be5\u662f\u4f7f\u8bbe\u7f6e\u7acb\u5373\u751f\u6548&#xff09; \u63d0\u793a&#xff1a;\u8bf7\u6839\u636e\u9700\u8981\u8fdb\u884c\u8fdb\u884c\u914d\u7f6e<\/li>\n<p>\u767b\u5f55MySQL&#xff1a; \u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55MySQL&#xff1a;<\/p>\n<p>mysql -u root -p<\/p>\n<p>\u8f93\u5165\u60a8\u5728\u5b89\u88c5\u6216\u5b89\u5168\u914d\u7f6e\u65f6\u8bbe\u7f6e\u7684root\u5bc6\u7801\u3002<\/p>\n<p>\u9a8c\u8bc1\u5b89\u88c5&#xff1a; \u767b\u5f55\u540e&#xff0c;\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5MySQL\u7684\u7248\u672c&#xff0c;\u4ee5\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f&#xff1a;<\/p>\n<p><span class=\"token keyword\">SELECT<\/span> VERSION<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h2>\u589e\u52a0\u6570\u636e\u5e93\u6301\u6709\u7528\u6237<\/h2>\n<p>\u5728MySQL\u4e2d\u589e\u52a0\u65b0\u7528\u6237\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b&#xff0c;\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u767b\u5f55MySQL&#xff1a; \u9996\u5148&#xff0c;\u60a8\u9700\u8981\u4ee5\u5177\u6709\u8db3\u591f\u6743\u9650\u7684\u7528\u6237&#xff08;\u901a\u5e38\u662froot\u7528\u6237&#xff09;\u767b\u5f55\u5230MySQL\u670d\u52a1\u5668\u3002<\/p>\n<p> mysql -u root -p<\/p>\n<p>\u8f93\u5165\u5bc6\u7801\u540e\u767b\u5f55\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u65b0\u7528\u6237&#xff1a; \u4f7f\u7528CREATE USER\u8bed\u53e5\u521b\u5efa\u65b0\u7528\u6237\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u60a8\u60f3\u521b\u5efa\u4e00\u4e2a\u540d\u4e3anewuser\u7684\u65b0\u7528\u6237&#xff0c;\u5e76\u4e14\u8be5\u7528\u6237\u53ea\u80fd\u4ece\u672c\u5730\u8ba1\u7b97\u673a\u8bbf\u95ee\u6570\u636e\u5e93&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p> <span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">USER<\/span> <span class=\"token string\">&#039;newuser&#039;<\/span><span class=\"token variable\">&#064;&#039;localhost&#039;<\/span> IDENTIFIED <span class=\"token keyword\">BY<\/span> <span class=\"token string\">&#039;password&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5c06newuser\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u7684\u7528\u6237\u540d&#xff0c;password\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u8bbe\u7f6e\u7684\u5bc6\u7801\u3002<\/p>\n<\/li>\n<li>\n<p>\u6388\u4e88\u6743\u9650&#xff1a; \u521b\u5efa\u7528\u6237\u540e&#xff0c;\u60a8\u9700\u8981\u4e3a\u8be5\u7528\u6237\u6388\u4e88\u6743\u9650\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u60a8\u60f3\u6388\u4e88\u65b0\u7528\u6237\u5bf9\u6240\u6709\u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p> <span class=\"token keyword\">GRANT<\/span> <span class=\"token keyword\">ALL<\/span> <span class=\"token keyword\">PRIVILEGES<\/span> <span class=\"token keyword\">ON<\/span> <span class=\"token operator\">*<\/span><span class=\"token punctuation\">.<\/span><span class=\"token operator\">*<\/span> <span class=\"token keyword\">TO<\/span> <span class=\"token string\">&#039;newuser&#039;<\/span><span class=\"token variable\">&#064;&#039;localhost&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\u6743\u9650\u548c\u6570\u636e\u5e93\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u5237\u65b0\u6743\u9650&#xff1a; \u6388\u4e88\u6743\u9650\u540e&#xff0c;\u60a8\u9700\u8981\u5237\u65b0\u6743\u9650\u8868&#xff0c;\u4f7f\u6743\u9650\u66f4\u6539\u7acb\u5373\u751f\u6548\u3002<\/p>\n<p> FLUSH <span class=\"token keyword\">PRIVILEGES<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u9000\u51faMySQL&#xff1a; \u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e&#xff0c;\u60a8\u53ef\u4ee5\u9000\u51faMySQL\u547d\u4ee4\u884c\u3002<\/p>\n<p> <span class=\"token keyword\">EXIT<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<p>\u8bf7\u6ce8\u610f&#xff0c;\u51fa\u4e8e\u5b89\u5168\u8003\u8651&#xff0c;\u60a8\u5e94\u8be5\u4ec5\u6388\u4e88\u7528\u6237\u6240\u9700\u7684\u6700\u5c0f\u6743\u9650&#xff0c;\u5e76\u4e14\u5e94\u8be5\u4f7f\u7528\u5f3a\u5bc6\u7801\u3002\u6b64\u5916&#xff0c;\u5982\u679c\u60a8\u5e0c\u671b\u7528\u6237\u80fd\u591f\u4ece\u4efb\u4f55\u4e3b\u673a\u8fde\u63a5\u5230MySQL\u670d\u52a1\u5668&#xff0c;\u53ef\u4ee5\u5c06&#039;localhost&#039;\u66ff\u6362\u4e3a&#039;%&#039;&#xff0c;\u4f46\u8fd9\u53ef\u80fd\u4f1a\u589e\u52a0\u5b89\u5168\u98ce\u9669\u3002<\/p>\n<h2>\u521b\u5efa\u6570\u636e\u5e93\u5e76\u589e\u52a0\u8868<\/h2>\n<p>\u5728MySQL\u4e2d\u589e\u52a0\u6570\u636e\u5e93\u5e76\u521b\u5efa\u8868\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u7684\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u589e\u52a0\u6570\u636e\u5e93<\/li>\n<p>\u9996\u5148&#xff0c;\u60a8\u9700\u8981\u767b\u5f55\u5230MySQL\u670d\u52a1\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55&#xff1a;<\/p>\n<p>mysql -u root -p<\/p>\n<p>\u8f93\u5165\u60a8\u7684\u5bc6\u7801\u540e&#xff0c;\u60a8\u5c06\u8fdb\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002\u7136\u540e&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528CREATE DATABASE\u8bed\u53e5\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93&#xff1a;<\/p>\n<p><span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">DATABASE<\/span> mydatabase<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5c06mydatabase\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/p>\n<li>\u521b\u5efa\u8868<\/li>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u540e&#xff0c;\u60a8\u9700\u8981\u9009\u62e9&#xff08;\u6216\u201c\u4f7f\u7528\u201d&#xff09;\u8be5\u6570\u636e\u5e93&#xff0c;\u4ee5\u4fbf\u5728\u5176\u4e2d\u521b\u5efa\u8868&#xff1a;<\/p>\n<p><span class=\"token keyword\">USE<\/span> mydatabase<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7136\u540e&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528CREATE TABLE\u8bed\u53e5\u6765\u521b\u5efa\u8868\u3002\u4f8b\u5982&#xff0c;\u521b\u5efa\u4e00\u4e2a\u540d\u4e3ausers\u7684\u8868&#xff0c;\u5305\u542bid\u3001username\u548cemail\u4e09\u4e2a\u5b57\u6bb5&#xff1a;<\/p>\n<p><span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> users <span class=\"token punctuation\">(<\/span><br \/>\n  id <span class=\"token keyword\">INT<\/span> <span class=\"token keyword\">AUTO_INCREMENT<\/span> <span class=\"token keyword\">PRIMARY<\/span> <span class=\"token keyword\">KEY<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  username <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  email <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u91cc&#xff0c;id\u5b57\u6bb5\u88ab\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u9012\u589e\u7684\u4e3b\u952e&#xff0c;username\u548cemail\u5b57\u6bb5\u88ab\u8bbe\u7f6e\u4e3a\u975e\u7a7a\u7684\u53d8\u957f\u5b57\u7b26\u4e32\u3002<\/p>\n<li>\u68c0\u67e5\u521b\u5efa\u7684\u6570\u636e\u5e93\u548c\u8868<\/li>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\u540e&#xff0c;\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u5df2\u6210\u529f\u521b\u5efa&#xff1a;<\/p>\n<p><span class=\"token keyword\">SHOW<\/span> <span class=\"token keyword\">DATABASES<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u5c06\u5217\u51fa\u6240\u6709\u6570\u636e\u5e93&#xff0c;\u60a8\u53ef\u4ee5\u68c0\u67e5\u60a8\u7684\u65b0\u6570\u636e\u5e93\u662f\u5426\u5728\u5217\u8868\u4e2d\u3002<\/p>\n<p><span class=\"token keyword\">SHOW<\/span> <span class=\"token keyword\">TABLES<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u5c06\u5217\u51fa\u60a8\u5f53\u524d\u9009\u62e9\u7684\u6570\u636e\u5e93\u4e2d\u7684\u6240\u6709\u8868&#xff0c;\u60a8\u53ef\u4ee5\u68c0\u67e5\u60a8\u7684\u65b0\u8868\u662f\u5426\u5728\u5217\u8868\u4e2d\u3002<\/p>\n<p><span class=\"token keyword\">DESCRIBE<\/span> users<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u5c06\u663e\u793ausers\u8868\u7684\u7ed3\u6784&#xff0c;\u5305\u62ec\u6bcf\u4e2a\u5b57\u6bb5\u7684\u540d\u79f0\u3001\u7c7b\u578b\u548c\u5176\u4ed6\u5c5e\u6027\u3002<\/p>\n<li>\u9000\u51faMySQL<\/li>\n<p>\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e&#xff0c;\u60a8\u53ef\u4ee5\u9000\u51faMySQL\u547d\u4ee4\u884c&#xff1a;<\/p>\n<p><span class=\"token keyword\">EXIT<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u4e9b\u6b65\u9aa4\u63d0\u4f9b\u4e86\u5728MySQL\u4e2d\u589e\u52a0\u6570\u636e\u5e93\u548c\u521b\u5efa\u8868\u7684\u57fa\u672c\u6d41\u7a0b\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\u6570\u636e\u5e93\u548c\u8868\u7684\u540d\u79f0\u3001\u5b57\u6bb5\u548c\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<h2>\u6d4b\u8bd5\u6570\u636e\u5e93\u8fde\u63a5<\/h2>\n<p>\u8fd9\u91cc\u4f7f\u7528\u7684\u662fpython\u7684pymysql\u5e93&#xff0c;\u5982\u679c\u8fde\u63a5\u6210\u529f\u7684\u8bdd&#xff0c;\u4f1a\u6253\u5370\u6570\u636e\u5e93\u7248\u672c\u53f7\u3002 \u4e00\u5b9a\u8981\u628a\u5b89\u5168\u7ec4\u914d\u7f6e\u597d&#xff0c;\u56e0\u4e3a\u6570\u636e\u5e93\u9ed8\u8ba4\u7aef\u53e3\u662f3306&#xff0c;\u8bb0\u5f97\u5f00\u542f&#xff0c;\u5426\u5219\u53ef\u80fd\u8fde\u63a5\u4e0d\u4e0a\u6570\u636e\u5e93<\/p>\n<p><span class=\"token keyword\">import<\/span> pymysql<\/p>\n<p><span class=\"token comment\"># \u8fde\u63a5\u5230MySQL\u6570\u636e\u5e93<\/span><br \/>\nconnection <span class=\"token operator\">&#061;<\/span> pymysql<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span><br \/>\n    host<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;localhost&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    user<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u4f60\u7684\u6570\u636e\u5e93\u7528\u6237\u540d&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    password<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u4f60\u7684\u6570\u636e\u5e93\u5bc6\u7801&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    database<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u4f60\u521b\u5efa\u7684\u6570\u636e\u5e93\u540d&#039;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u521b\u5efa\u4e00\u4e2a\u6e38\u6807\u5bf9\u8c61<\/span><br \/>\n    <span class=\"token keyword\">with<\/span> connection<span class=\"token punctuation\">.<\/span>cursor<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> cursor<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u6267\u884cSQL\u67e5\u8be2<\/span><br \/>\n        sql <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;SELECT VERSION()&#034;<\/span><br \/>\n        cursor<span class=\"token punctuation\">.<\/span>execute<span class=\"token punctuation\">(<\/span>sql<span class=\"token punctuation\">)<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> cursor<span class=\"token punctuation\">.<\/span>fetchone<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Database version : %s &#034;<\/span> <span class=\"token operator\">%<\/span> result<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">finally<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u5173\u95ed\u8fde\u63a5<\/span><br \/>\n    connection<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u8fd9\u91cc\u4e3b\u8981\u5199\u5230\u4e86\u6570\u636e\u5e93\u7684\u8fde\u63a5&#xff0c;\u5177\u4f53\u7684\u8868\u7684\u521b\u5efa\u548c\u6570\u636e\u7684\u589e\u5220\u6539\u67e5\u7b49\u64cd\u4f5c\u53d6\u51b3\u4e8e\u4ee3\u7801\u4e2d\u7684\u903b\u8f91\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u963f\u91cc\u4e91\u6570\u636e\u5e93\u5b89\u88c5\u53ca\u521b\u5efa\uff0c\u4e0epymysql\u7684\u5e93\u7684\u8fde\u63a5\u8fc7\u7a0b\u3002_\u963f\u91cc\u4e91ubuntu mysql<\/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":[114,43,96],"topic":[],"class_list":["post-18975","post","type-post","status-publish","format-standard","hentry","category-server","tag-mysql","tag-43","tag-96"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \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\/18975.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u963f\u91cc\u4e91\u6570\u636e\u5e93\u5b89\u88c5\u53ca\u521b\u5efa\uff0c\u4e0epymysql\u7684\u5e93\u7684\u8fde\u63a5\u8fc7\u7a0b\u3002_\u963f\u91cc\u4e91ubuntu mysql\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/18975.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T17:22:09+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\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18975.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/18975.html\",\"name\":\"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T17:22:09+00:00\",\"dateModified\":\"2025-04-18T17:22:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/18975.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/18975.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18975.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668\"}]},{\"@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":"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \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\/18975.html","og_locale":"zh_CN","og_type":"article","og_title":"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u963f\u91cc\u4e91\u6570\u636e\u5e93\u5b89\u88c5\u53ca\u521b\u5efa\uff0c\u4e0epymysql\u7684\u5e93\u7684\u8fde\u63a5\u8fc7\u7a0b\u3002_\u963f\u91cc\u4e91ubuntu mysql","og_url":"https:\/\/www.wsisp.com\/helps\/18975.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T17:22:09+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/18975.html","url":"https:\/\/www.wsisp.com\/helps\/18975.html","name":"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T17:22:09+00:00","dateModified":"2025-04-18T17:22:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/18975.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/18975.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/18975.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u963f\u91cc\u4e91\u670d\u52a1\u5668\u5b89\u88c5MySQL\u670d\u52a1\u5668"}]},{"@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\/18975","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=18975"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18975\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=18975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=18975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=18975"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=18975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}