{"id":160041,"date":"2024-11-03T19:47:22","date_gmt":"2024-11-03T11:47:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160041\/"},"modified":"2024-11-03T19:47:23","modified_gmt":"2024-11-03T11:47:23","slug":"mysql-%e6%95%99%e7%a8%8b-mysql-%e9%80%a3%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160041\/","title":{"rendered":"MYSQL \u6559\u7a0b MySQL \u9023\u63a5"},"content":{"rendered":"<h1 id=\"mysql-%e6%95%99%e7%a8%8b%ef%bc%9amysql-%e9%80%a3%e6%8e%a5-YvaZbNFXUd\">MySQL \u6559\u7a0b\uff1aMySQL \u9023\u63a5<\/h1>\n<p>MySQL \u662f\u4e00\u7a2e\u6d41\u884c\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u7db2\u7ad9\u9084\u662f\u5927\u578b\u4f01\u696d\u7cfb\u7d71\uff0cMySQL \u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u5982\u4f55\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u57fa\u672c\u7684\u9023\u63a5\u793a\u4f8b\u548c\u6ce8\u610f\u4e8b\u9805\u3002<\/p>\n<h2 id=\"1-%e4%bb%80%e9%ba%bc%e6%98%af-mysql-%e9%80%a3%e6%8e%a5%ef%bc%9f-YvaZbNFXUd\">1. \u4ec0\u9ebc\u662f MySQL \u9023\u63a5\uff1f<\/h2>\n<p>MySQL \u9023\u63a5\u662f\u6307\u61c9\u7528\u7a0b\u5e8f\u8207 MySQL \u6578\u64da\u5eab\u4e4b\u9593\u7684\u901a\u4fe1\u904e\u7a0b\u3002\u901a\u904e\u9019\u7a2e\u9023\u63a5\uff0c\u61c9\u7528\u7a0b\u5e8f\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\uff0c\u8b80\u53d6\u548c\u5beb\u5165\u6578\u64da\u3002\u9023\u63a5\u7684\u5efa\u7acb\u901a\u5e38\u9700\u8981\u63d0\u4f9b\u6578\u64da\u5eab\u7684\u4e3b\u6a5f\u540d\u3001\u7528\u6236\u540d\u3001\u5bc6\u78bc\u548c\u6578\u64da\u5eab\u540d\u7a31\u7b49\u4fe1\u606f\u3002<\/p>\n<h2 id=\"2-%e9%80%a3%e6%8e%a5-mysql-%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-YvaZbNFXUd\">2. \u9023\u63a5 MySQL \u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u8981\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\uff0c\u60a8\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5b89\u88dd MySQL \u5ba2\u6236\u7aef\u6216\u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\u7684 MySQL \u5eab\u3002<\/li>\n<li>\u7372\u53d6\u6578\u64da\u5eab\u7684\u9023\u63a5\u4fe1\u606f\uff0c\u5305\u62ec\u4e3b\u6a5f\u540d\u3001\u7528\u6236\u540d\u3001\u5bc6\u78bc\u548c\u6578\u64da\u5eab\u540d\u7a31\u3002<\/li>\n<li>\u4f7f\u7528\u9069\u7576\u7684\u8a9e\u6cd5\u5efa\u7acb\u9023\u63a5\u3002<\/li>\n<\/ul>\n<h2 id=\"3-%e4%bd%bf%e7%94%a8-php-%e9%80%a3%e6%8e%a5-mysql-YvaZbNFXUd\">3. \u4f7f\u7528 PHP \u9023\u63a5 MySQL<\/h2>\n<p>PHP \u662f\u4e00\u7a2e\u5e38\u7528\u7684\u7db2\u9801\u958b\u767c\u8a9e\u8a00\uff0c\u8207 MySQL \u7684\u7d50\u5408\u975e\u5e38\u666e\u904d\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 PHP \u9023\u63a5 MySQL \u7684\u57fa\u672c\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\"; \/\/ \u6578\u64da\u5eab\u4e3b\u6a5f\u540d\n$username = \"username\"; \/\/ \u6578\u64da\u5eab\u7528\u6236\u540d\n$password = \"password\"; \/\/ \u6578\u64da\u5eab\u5bc6\u78bc\n$dbname = \"database_name\"; \/\/ \u6578\u64da\u5eab\u540d\u7a31\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\necho \"\u6210\u529f\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\";\n?&gt;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 MySQLi \u64f4\u5c55\u4f86\u5efa\u7acb\u9023\u63a5\u3002\u9996\u5148\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u6578\u64da\u5eab\u7684\u4e3b\u6a5f\u540d\u3001\u7528\u6236\u540d\u3001\u5bc6\u78bc\u548c\u6578\u64da\u5eab\u540d\u7a31\u3002\u7136\u5f8c\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u65b0\u7684 MySQLi \u5c0d\u8c61\uff0c\u4e26\u6aa2\u67e5\u9023\u63a5\u662f\u5426\u6210\u529f\u3002<\/p>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8-python-%e9%80%a3%e6%8e%a5-mysql-YvaZbNFXUd\">4. \u4f7f\u7528 Python \u9023\u63a5 MySQL<\/h2>\n<p>Python \u4e5f\u662f\u4e00\u7a2e\u6d41\u884c\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u4e26\u4e14\u6709\u591a\u500b\u5eab\u53ef\u4ee5\u7528\u4f86\u9023\u63a5 MySQL\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Python \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import mysql.connector\n\n# \u5efa\u7acb\u9023\u63a5\nconn = mysql.connector.connect(\n    host=\"localhost\",\n    user=\"username\",\n    password=\"password\",\n    database=\"database_name\"\n)\n\n# \u6aa2\u67e5\u9023\u63a5\nif conn.is_connected():\n    print(\"\u6210\u529f\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\")\nelse:\n    print(\"\u9023\u63a5\u5931\u6557\")\n?&gt;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 mysql-connector-python \u5eab\u4f86\u5efa\u7acb\u9023\u63a5\u3002\u8207 PHP \u7684\u793a\u4f8b\u985e\u4f3c\uff0c\u6211\u5011\u63d0\u4f9b\u4e86\u4e3b\u6a5f\u540d\u3001\u7528\u6236\u540d\u3001\u5bc6\u78bc\u548c\u6578\u64da\u5eab\u540d\u7a31\uff0c\u7136\u5f8c\u6aa2\u67e5\u9023\u63a5\u72c0\u614b\u3002<\/p>\n<h2 id=\"5-%e9%80%a3%e6%8e%a5%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-YvaZbNFXUd\">5. \u9023\u63a5\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9023\u63a5 MySQL \u6578\u64da\u5eab\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd MySQL \u670d\u52d9\u6b63\u5728\u904b\u884c\u3002<\/li>\n<li>\u6aa2\u67e5\u9632\u706b\u7246\u8a2d\u7f6e\uff0c\u78ba\u4fdd\u5141\u8a31\u9023\u63a5\u5230 MySQL \u7684\u7aef\u53e3\uff08\u9ed8\u8a8d\u70ba 3306\uff09\u3002<\/li>\n<li>\u4f7f\u7528\u5f37\u5bc6\u78bc\u4f86\u4fdd\u8b77\u6578\u64da\u5eab\u7528\u6236\u3002<\/li>\n<li>\u5b9a\u671f\u66f4\u65b0 MySQL \u7248\u672c\uff0c\u4ee5\u7372\u53d6\u6700\u65b0\u7684\u5b89\u5168\u6027\u548c\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-YvaZbNFXUd\">\u7e3d\u7d50<\/h2>\n<p>MySQL \u9023\u63a5\u662f\u61c9\u7528\u7a0b\u5e8f\u8207\u6578\u64da\u5eab\u4e4b\u9593\u7684\u95dc\u9375\u6b65\u9a5f\uff0c\u6b63\u78ba\u7684\u9023\u63a5\u65b9\u5f0f\u80fd\u5920\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u548c\u9ad8\u6548\u5b58\u53d6\u3002\u7121\u8ad6\u60a8\u662f\u4f7f\u7528 PHP \u9084\u662f Python\uff0c\u5efa\u7acb\u9023\u63a5\u7684\u57fa\u672c\u6b65\u9a5f\u90fd\u662f\u76f8\u4f3c\u7684\u3002\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u9023\u63a5 MySQL \u6578\u64da\u5eab\uff0c\u5c0d\u65bc\u958b\u767c\u548c\u7dad\u8b77\u61c9\u7528\u7a0b\u5e8f\u81f3\u95dc\u91cd\u8981\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u4f86\u904b\u884c\u60a8\u7684 MySQL \u6578\u64da\u5eab\uff0c\u8acb\u8003\u616e\u9078\u64c7\u5408\u9069\u7684\u670d\u52d9\u63d0\u4f9b\u5546\u4ee5\u7372\u5f97\u6700\u4f73\u6027\u80fd\u548c\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 MySQL \u9023\u63a5\u8cc7\u6599\u5eab\uff0c\u638c\u63e1\u57fa\u672c\u64cd\u4f5c\u8207\u6280\u5de7\uff0c\u5feb\u901f\u4e0a\u624b MySQL \u6559\u7a0b\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u80fd\u529b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-160041","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=160041"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160041\/revisions"}],"predecessor-version":[{"id":160042,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160041\/revisions\/160042"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}