{"id":76390,"date":"2024-10-16T06:16:17","date_gmt":"2024-10-15T22:16:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76390\/"},"modified":"2024-10-16T06:16:17","modified_gmt":"2024-10-15T22:16:17","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae%e5%af%a6%e6%88%b0%e6%bc%94%e7%b7%b4","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76390\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u5b89\u88dd\u8207\u914d\u7f6e\u5be6\u6230\u6f14\u7df4"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae%e5%af%a6%e6%88%b0%e6%bc%94%e7%b7%b4-BrIzJWVAqS\">MySQL\u6578\u64da\u5eab\u5b89\u88dd\u8207\u914d\u7f6e\u5be6\u6230\u6f14\u7df4<\/h1>\n<p>MySQL\u662f\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u4f01\u696d\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u4ecb\u7d39MySQL\u7684\u5b89\u88dd\u8207\u914d\u7f6e\u904e\u7a0b\uff0c\u5e6b\u52a9\u8b80\u8005\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9dmysql-BrIzJWVAqS\">\u4e00\u3001\u5b89\u88ddMySQL<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684\u4f3a\u670d\u5668\u74b0\u5883\u7b26\u5408MySQL\u7684\u5b89\u88dd\u8981\u6c42\u3002\u4ee5\u4e0b\u662f\u5b89\u88ddMySQL\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-BrIzJWVAqS\">1. \u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h3 id=\"2-%e5%ae%89%e8%a3%9dmysql-BrIzJWVAqS\">2. \u5b89\u88ddMySQL<\/h3>\n<p>\u5728Ubuntu\u7cfb\u7d71\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88ddMySQL\uff1a<\/p>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<h3 id=\"3-%e5%95%9f%e5%8b%95mysql%e6%9c%8d%e5%8b%99-BrIzJWVAqS\">3. \u555f\u52d5MySQL\u670d\u52d9<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5MySQL\u670d\u52d9\u4e26\u8a2d\u7f6e\u5176\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start mysql\nsudo systemctl enable mysql<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e9%85%8d%e7%bd%aemysql-BrIzJWVAqS\">\u4e8c\u3001\u914d\u7f6eMySQL<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u9032\u884c\u57fa\u672c\u914d\u7f6e\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\u3002<\/p>\n<h3 id=\"1-%e5%9f%b7%e8%a1%8c%e5%ae%89%e5%85%a8%e6%80%a7%e8%85%b3%e6%9c%ac-BrIzJWVAqS\">1. \u57f7\u884c\u5b89\u5168\u6027\u8173\u672c<\/h3>\n<p>MySQL\u63d0\u4f9b\u4e86\u4e00\u500b\u5b89\u5168\u6027\u8173\u672c\uff0c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u9032\u884c\u57fa\u672c\u7684\u5b89\u5168\u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u5728\u57f7\u884c\u6b64\u547d\u4ee4\u5f8c\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u7528\u6236\u8a2d\u7f6eroot\u5bc6\u78bc\u3001\u522a\u9664\u533f\u540d\u7528\u6236\u3001\u7981\u6b62root\u9060\u7a0b\u767b\u9304\u7b49\u9078\u9805\u3002\u5efa\u8b70\u6839\u64da\u63d0\u793a\u9032\u884c\u914d\u7f6e\u3002<\/p>\n<h3 id=\"2-%e7%99%bb%e9%8c%84mysql-BrIzJWVAqS\">2. \u767b\u9304MySQL<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u8f38\u5165\u5bc6\u78bc\u5f8c\uff0c\u5373\u53ef\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e7%94%a8%e6%88%b6-BrIzJWVAqS\">3. \u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h3>\n<p>\u5728MySQL\u4e2d\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u57fa\u672c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database;\nCREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;<\/code><\/pre>\n<p>\u9019\u4e9b\u547d\u4ee4\u5c07\u5275\u5efa\u4e00\u500b\u540d\u70bamy_database\u7684\u6578\u64da\u5eab\u548c\u4e00\u500b\u7528\u6236my_user\uff0c\u4e26\u6388\u4e88\u8a72\u7528\u6236\u5c0d\u6578\u64da\u5eab\u7684\u6240\u6709\u6b0a\u9650\u3002<\/p>\n<h2 id=\"%e4%b8%89%e3%80%81%e6%b8%ac%e8%a9%a6mysql%e9%85%8d%e7%bd%ae-BrIzJWVAqS\">\u4e09\u3001\u6e2c\u8a66MySQL\u914d\u7f6e<\/h2>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684\u8868\u4f86\u6e2c\u8a66MySQL\u662f\u5426\u6b63\u5e38\u904b\u884c\uff1a<\/p>\n<pre><code>USE my_database;\nCREATE TABLE test_table (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(100) NOT NULL\n);\nINSERT INTO test_table (name) VALUES ('\u6e2c\u8a66\u6578\u64da');<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u8a62\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT * FROM test_table;<\/code><\/pre>\n<p>\u5982\u679c\u80fd\u5920\u6210\u529f\u67e5\u8a62\u5230\u6578\u64da\uff0c\u5247\u8868\u793aMySQL\u5df2\u7d93\u6b63\u78ba\u5b89\u88dd\u548c\u914d\u7f6e\u3002<\/p>\n<h2 id=\"%e5%9b%9b%e3%80%81%e5%b8%b8%e8%a6%8b%e5%95%8f%e9%a1%8c%e5%8f%8a%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-BrIzJWVAqS\">\u56db\u3001\u5e38\u898b\u554f\u984c\u53ca\u89e3\u6c7a\u65b9\u6848<\/h2>\n<ul>\n<li><strong>\u7121\u6cd5\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/strong>\u6aa2\u67e5\u7cfb\u7d71\u65e5\u8a8c\u4ee5\u7372\u53d6\u932f\u8aa4\u4fe1\u606f\uff0c\u4e26\u78ba\u4fdd\u6240\u6709\u4f9d\u8cf4\u9805\u5df2\u6b63\u78ba\u5b89\u88dd\u3002<\/li>\n<li><strong>\u7121\u6cd5\u767b\u9304MySQL\uff1a<\/strong>\u78ba\u8a8d\u4f7f\u7528\u7684\u7528\u6236\u540d\u548c\u5bc6\u78bc\u6b63\u78ba\uff0c\u4e26\u6aa2\u67e5\u7528\u6236\u6b0a\u9650\u8a2d\u7f6e\u3002<\/li>\n<li><strong>\u6027\u80fd\u554f\u984c\uff1a<\/strong>\u8003\u616e\u8abf\u6574MySQL\u914d\u7f6e\u6587\u4ef6\uff08my.cnf\uff09\u4e2d\u7684\u53c3\u6578\uff0c\u4ee5\u512a\u5316\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BrIzJWVAqS\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86MySQL\u7684\u5b89\u88dd\u8207\u914d\u7f6e\u904e\u7a0b\uff0c\u5f9e\u7cfb\u7d71\u66f4\u65b0\u5230\u6578\u64da\u5eab\u5275\u5efa\uff0c\u6db5\u84cb\u4e86\u57fa\u672c\u7684\u64cd\u4f5c\u6b65\u9a5f\u3002\u7121\u8ad6\u662f\u958b\u767c\u8005\u9084\u662f\u7cfb\u7d71\u7ba1\u7406\u54e1\uff0c\u638c\u63e1MySQL\u7684\u5b89\u88dd\u8207\u914d\u7f6e\u90fd\u662f\u4e00\u9805\u91cd\u8981\u6280\u80fd\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72\u60a8\u7684MySQL\u6578\u64da\u5eab\uff0c\u4eab\u53d7\u9ad8\u6548\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1MySQL\u6578\u64da\u5eab\u5b89\u88dd\u8207\u914d\u7f6e\u7684\u5be6\u6230\u6280\u5de7\uff0c\u5f9e\u57fa\u790e\u5230\u9032\u968e\uff0c\u8f15\u9b06\u61c9\u5c0d\u5404\u7a2e\u6578\u64da\u7ba1\u7406\u6311\u6230\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-76390","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76390","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=76390"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76390\/revisions"}],"predecessor-version":[{"id":76391,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76390\/revisions\/76391"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}