{"id":75696,"date":"2024-10-16T00:27:17","date_gmt":"2024-10-15T16:27:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/75696\/"},"modified":"2024-10-16T00:27:17","modified_gmt":"2024-10-15T16:27:17","slug":"mysql-5-0%e5%ae%89%e8%a3%9dmysql%e5%92%8cphp%e6%90%ad%e9%85%8d%e4%b9%8b%e6%9c%80%e4%bd%b3%e7%b5%84%e5%90%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/75696\/","title":{"rendered":"MySQL 5.0\u5b89\u88ddMySQL(\u548cPHP\u642d\u914d\u4e4b\u6700\u4f73\u7d44\u5408)"},"content":{"rendered":"<h1 id=\"mysql-5-0%e5%ae%89%e8%a3%9dmysql%e5%92%8cphp%e6%90%ad%e9%85%8d%e4%b9%8b%e6%9c%80%e4%bd%b3%e7%b5%84%e5%90%88-oOtHzIHFJM\">MySQL 5.0\u5b89\u88ddMySQL(\u548cPHP\u642d\u914d\u4e4b\u6700\u4f73\u7d44\u5408)<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u7684\u9078\u64c7\u5c0d\u65bc\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u81f3\u95dc\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u958b\u6e90\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u56e0\u5176\u9ad8\u6548\u3001\u9748\u6d3b\u548c\u6613\u65bc\u4f7f\u7528\u800c\u53d7\u5230\u5ee3\u6cdb\u6b61\u8fce\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u4f3a\u670d\u5668\u4e0a\u5b89\u88ddMySQL 5.0\uff0c\u4e26\u63a2\u8a0e\u5176\u8207PHP\u7684\u6700\u4f73\u642d\u914d\u3002<\/p>\n<h2 id=\"mysql-5-0%e7%9a%84%e7%89%b9%e9%bb%9e-oOtHzIHFJM\">MySQL 5.0\u7684\u7279\u9ede<\/h2>\n<p>MySQL 5.0\u5f15\u5165\u4e86\u8a31\u591a\u65b0\u7279\u6027\uff0c\u4f7f\u5176\u6210\u70ba\u958b\u767c\u8005\u7684\u7406\u60f3\u9078\u64c7\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4e3b\u8981\u7279\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u5b58\u5132\u904e\u7a0b\uff1a<\/strong>\u652f\u6301\u5b58\u5132\u904e\u7a0b\uff0c\u5141\u8a31\u7528\u6236\u5728\u6578\u64da\u5eab\u4e2d\u57f7\u884c\u8907\u96dc\u7684\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u89f8\u767c\u5668\uff1a<\/strong>\u53ef\u4ee5\u5728\u6578\u64da\u8868\u4e0a\u8a2d\u7f6e\u89f8\u767c\u5668\uff0c\u81ea\u52d5\u57f7\u884c\u7279\u5b9a\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u8996\u5716\uff1a<\/strong>\u652f\u6301\u8996\u5716\u7684\u5275\u5efa\uff0c\u65b9\u4fbf\u7528\u6236\u9032\u884c\u6578\u64da\u67e5\u8a62\u3002<\/li>\n<li><strong>\u4e8b\u52d9\u652f\u6301\uff1a<\/strong>\u63d0\u4f9b\u4e8b\u52d9\u652f\u6301\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql-5-0-oOtHzIHFJM\">\u5b89\u88ddMySQL 5.0<\/h2>\n<p>\u4ee5\u4e0b\u662f\u5b89\u88ddMySQL 5.0\u7684\u6b65\u9a5f\uff0c\u5047\u8a2d\u60a8\u4f7f\u7528\u7684\u662fLinux\u7cfb\u7d71\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f1%ef%bc%9a%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-oOtHzIHFJM\">\u6b65\u9a5f1\uff1a\u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo apt-get update<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f2%ef%bc%9a%e5%ae%89%e8%a3%9dmysql-oOtHzIHFJM\">\u6b65\u9a5f2\uff1a\u5b89\u88ddMySQL<\/h3>\n<pre><code>sudo apt-get install mysql-server-5.0<\/code><\/pre>\n<p>\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8a2d\u7f6eMySQL\u7684root\u7528\u6236\u5bc6\u78bc\u3002\u8acb\u52d9\u5fc5\u8a18\u4f4f\u9019\u500b\u5bc6\u78bc\uff0c\u56e0\u70ba\u5f8c\u7e8c\u7684\u6578\u64da\u5eab\u7ba1\u7406\u5c07\u9700\u8981\u7528\u5230\u5b83\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f3%ef%bc%9a%e5%95%9f%e5%8b%95mysql%e6%9c%8d%e5%8b%99-oOtHzIHFJM\">\u6b65\u9a5f3\uff1a\u555f\u52d5MySQL\u670d\u52d9<\/h3>\n<pre><code>sudo service mysql start<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f4%ef%bc%9a%e6%aa%a2%e6%9f%a5%e5%ae%89%e8%a3%9d%e7%8b%80%e6%85%8b-oOtHzIHFJM\">\u6b65\u9a5f4\uff1a\u6aa2\u67e5\u5b89\u88dd\u72c0\u614b<\/h3>\n<pre><code>sudo service mysql status<\/code><\/pre>\n<p>\u5982\u679c\u986f\u793aMySQL\u6b63\u5728\u904b\u884c\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e9%85%8d%e7%bd%aemysql-oOtHzIHFJM\">\u914d\u7f6eMySQL<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u8f38\u5165\u60a8\u5728\u5b89\u88dd\u904e\u7a0b\u4e2d\u8a2d\u7f6e\u7684\u5bc6\u78bc\u5f8c\uff0c\u60a8\u5c07\u9032\u5165MySQL\u7684\u547d\u4ee4\u884c\u754c\u9762\u3002\u5728\u9019\u88e1\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u6578\u64da\u5eab\u3001\u7528\u6236\u4ee5\u53ca\u8a2d\u7f6e\u6b0a\u9650\u7b49\u3002<\/p>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-oOtHzIHFJM\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h3>\n<pre><code>CREATE DATABASE my_database;<\/code><\/pre>\n<pre><code>CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';<\/code><\/pre>\n<pre><code>GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';<\/code><\/pre>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<h2 id=\"mysql%e8%88%87php%e7%9a%84%e6%90%ad%e9%85%8d-oOtHzIHFJM\">MySQL\u8207PHP\u7684\u642d\u914d<\/h2>\n<p>MySQL\u8207PHP\u7684\u7d50\u5408\u662fWeb\u958b\u767c\u4e2d\u6700\u5e38\u898b\u7684\u7d44\u5408\u4e4b\u4e00\u3002\u4f7f\u7528PHP\u9023\u63a5MySQL\u6578\u64da\u5eab\u975e\u5e38\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"my_user\";\n$password = \"my_password\";\n$dbname = \"my_database\";\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 \"\u9023\u63a5\u6210\u529f\";\n?&gt;<\/code><\/pre>\n<p>\u5728\u9019\u6bb5\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528mysqli\u64f4\u5c55\u4f86\u9023\u63a5MySQL\u6578\u64da\u5eab\u3002\u78ba\u4fdd\u5728\u4f7f\u7528\u4e4b\u524d\u5df2\u7d93\u5b89\u88dd\u4e86mysqli\u64f4\u5c55\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-oOtHzIHFJM\">\u7e3d\u7d50<\/h2>\n<p>MySQL 5.0\u7684\u5b89\u88dd\u548c\u914d\u7f6e\u76f8\u5c0d\u7c21\u55ae\uff0c\u4e26\u4e14\u8207PHP\u7684\u642d\u914d\u4f7f\u5f97\u958b\u767c\u52d5\u614b\u7db2\u7ad9\u8b8a\u5f97\u66f4\u52a0\u9ad8\u6548\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u61c9\u7528\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u6578\u64da\u652f\u6301\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c\u60a8\u7684MySQL\u548cPHP\u61c9\u7528\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88ddMySQL 5.0\uff0c\u63a2\u7d22\u8207PHP\u642d\u914d\u7684\u6700\u4f73\u7d44\u5408\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u6578\u64da\u7ba1\u7406\u6548\u7387\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-75696","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75696","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=75696"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75696\/revisions"}],"predecessor-version":[{"id":75697,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75696\/revisions\/75697"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=75696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=75696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=75696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}