{"id":62309,"date":"2024-10-13T17:56:18","date_gmt":"2024-10-13T09:56:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/62309\/"},"modified":"2024-10-13T17:56:18","modified_gmt":"2024-10-13T09:56:18","slug":"linux%e4%b8%8bmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e9%96%8b%e7%99%bc%e6%8a%80%e8%a1%93","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/62309\/","title":{"rendered":"Linux\u4e0bMySQL\u6578\u64da\u5eab\u958b\u767c\u6280\u8853"},"content":{"rendered":"<h1 id=\"linux%e4%b8%8bmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e9%96%8b%e7%99%bc%e6%8a%80%e8%a1%93-SbMTRipbLh\">Linux\u4e0bMySQL\u6578\u64da\u5eab\u958b\u767c\u6280\u8853<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0cMySQL\u4f5c\u70ba\u4e00\u7a2e\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u7279\u5225\u662f\u5728Linux\u74b0\u5883\u4e0b\uff0cMySQL\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u4f7f\u5176\u6210\u70ba\u958b\u767c\u8005\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u63a2\u8a0eLinux\u4e0bMySQL\u6578\u64da\u5eab\u7684\u958b\u767c\u6280\u8853\uff0c\u5305\u62ec\u5b89\u88dd\u3001\u914d\u7f6e\u3001\u6578\u64da\u64cd\u4f5c\u53ca\u6027\u80fd\u512a\u5316\u7b49\u65b9\u9762\u3002<\/p>\n<h2 id=\"1-mysql%e7%9a%84%e5%ae%89%e8%a3%9d-SbMTRipbLh\">1. MySQL\u7684\u5b89\u88dd<\/h2>\n<p>\u5728Linux\u7cfb\u7d71\u4e0a\u5b89\u88ddMySQL\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5Ubuntu\u70ba\u4f8b\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install mysql-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5MySQL\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysql\n<\/code><\/pre>\n<p>\u70ba\u4e86\u78ba\u4fddMySQL\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable mysql\n<\/code><\/pre>\n<h2 id=\"2-mysql%e7%9a%84%e9%85%8d%e7%bd%ae-SbMTRipbLh\">2. MySQL\u7684\u914d\u7f6e<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u9032\u884c\u57fa\u672c\u914d\u7f6e\u662f\u5fc5\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>sudo mysql\n<\/code><\/pre>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u53ef\u4ee5\u8a2d\u7f6eroot\u7528\u6236\u7684\u5bc6\u78bc\uff0c\u4e26\u5275\u5efa\u65b0\u7684\u7528\u6236\u53ca\u6578\u64da\u5eab\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';\nCREATE DATABASE my_database;\nCREATE USER 'my_user'@'localhost' IDENTIFIED BY 'user_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n<h2 id=\"3-%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-SbMTRipbLh\">3. \u6578\u64da\u64cd\u4f5c<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u6578\u64da\u64cd\u4f5c\u4e3b\u8981\u901a\u904eSQL\u8a9e\u53e5\u9032\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u6578\u64da\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"3-1-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-SbMTRipbLh\">3.1 \u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>INSERT INTO my_table (column1, column2) VALUES ('value1', 'value2');\n<\/code><\/pre>\n<h3 id=\"3-2-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-SbMTRipbLh\">3.2 \u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>SELECT * FROM my_table WHERE column1 = 'value1';\n<\/code><\/pre>\n<h3 id=\"3-3-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-SbMTRipbLh\">3.3 \u66f4\u65b0\u6578\u64da<\/h3>\n<pre><code>UPDATE my_table SET column2 = 'new_value' WHERE column1 = 'value1';\n<\/code><\/pre>\n<h3 id=\"3-4-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-SbMTRipbLh\">3.4 \u522a\u9664\u6578\u64da<\/h3>\n<pre><code>DELETE FROM my_table WHERE column1 = 'value1';\n<\/code><\/pre>\n<h2 id=\"4-%e6%80%a7%e8%83%bd%e5%84%aa%e5%8c%96-SbMTRipbLh\">4. \u6027\u80fd\u512a\u5316<\/h2>\n<p>\u70ba\u4e86\u63d0\u9ad8MySQL\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u7d22\u5f15\uff1a<\/strong>\u70ba\u5e38\u7528\u7684\u67e5\u8a62\u5b57\u6bb5\u5275\u5efa\u7d22\u5f15\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u67e5\u8a62\u512a\u5316\uff1a<\/strong>\u4f7f\u7528EXPLAIN\u547d\u4ee4\u5206\u6790\u67e5\u8a62\u8a08\u5283\uff0c\u627e\u51fa\u6027\u80fd\u74f6\u9838\u3002<\/li>\n<li><strong>\u914d\u7f6e\u8abf\u6574\uff1a<\/strong>\u6839\u64da\u5be6\u969b\u9700\u6c42\u8abf\u6574MySQL\u7684\u914d\u7f6e\u6587\u4ef6\uff08my.cnf\uff09\uff0c\u5982\u8abf\u6574\u7de9\u885d\u5340\u5927\u5c0f\u7b49\u3002<\/li>\n<li><strong>\u5b9a\u671f\u7dad\u8b77\uff1a<\/strong>\u5b9a\u671f\u57f7\u884cOPTIMIZE TABLE\u547d\u4ee4\uff0c\u6e05\u7406\u788e\u7247\u3002<\/li>\n<\/ul>\n<h2 id=\"5-%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-SbMTRipbLh\">5. \u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u958b\u767c\u548c\u904b\u884cMySQL\u6578\u64da\u5eab\u6642\uff0c\u5b89\u5168\u6027\u662f\u4e0d\u53ef\u5ffd\u8996\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b89\u5168\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li>\u5b9a\u671f\u66f4\u65b0MySQL\u7248\u672c\uff0c\u4ee5\u4fee\u88dc\u5df2\u77e5\u7684\u5b89\u5168\u6f0f\u6d1e\u3002<\/li>\n<li>\u4f7f\u7528\u5f37\u5bc6\u78bc\uff0c\u4e26\u5b9a\u671f\u66f4\u63db\u3002<\/li>\n<li>\u9650\u5236\u7528\u6236\u7684\u8a2a\u554f\u6b0a\u9650\uff0c\u50c5\u6388\u4e88\u5fc5\u8981\u7684\u6b0a\u9650\u3002<\/li>\n<li>\u5b9a\u671f\u5099\u4efd\u6578\u64da\uff0c\u4ee5\u9632\u6578\u64da\u4e1f\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-SbMTRipbLh\">\u7e3d\u7d50<\/h2>\n<p>Linux\u4e0b\u7684MySQL\u6578\u64da\u5eab\u958b\u767c\u6280\u8853\u6db5\u84cb\u4e86\u5f9e\u5b89\u88dd\u3001\u914d\u7f6e\u5230\u6578\u64da\u64cd\u4f5c\u53ca\u6027\u80fd\u512a\u5316\u7684\u591a\u500b\u65b9\u9762\u3002\u638c\u63e1\u9019\u4e9b\u6280\u8853\u4e0d\u50c5\u80fd\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff0c\u9084\u80fd\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u7a69\u5b9a\u6027\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u7121\u8ad6\u662f\u9078\u64c7 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u80fd\u70ba\u60a8\u7684MySQL\u6578\u64da\u5eab\u63d0\u4f9b\u826f\u597d\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Linux\u4e0bMySQL\u6578\u64da\u5eab\u958b\u767c\u6280\u8853\uff0c\u638c\u63e1\u6578\u64da\u7ba1\u7406\u3001\u6027\u80fd\u512a\u5316\u53ca\u5b89\u5168\u6027\u63d0\u5347\u7684\u5be6\u7528\u6280\u5de7\u8207\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-62309","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62309","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=62309"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62309\/revisions"}],"predecessor-version":[{"id":62310,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62309\/revisions\/62310"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=62309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=62309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=62309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}