{"id":62285,"date":"2024-10-13T17:44:13","date_gmt":"2024-10-13T09:44:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/62285\/"},"modified":"2024-10-13T17:44:13","modified_gmt":"2024-10-13T09:44:13","slug":"linux%e7%92%b0%e5%a2%83%e5%ae%89%e8%a3%9dmysql%e9%9c%80%e5%88%9d%e5%a7%8b%e5%8c%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/62285\/","title":{"rendered":"Linux\u74b0\u5883\u5b89\u88ddMySQL\u9700\u521d\u59cb\u5316"},"content":{"rendered":"<h1 id=\"linux%e7%92%b0%e5%a2%83%e5%ae%89%e8%a3%9dmysql%e9%9c%80%e5%88%9d%e5%a7%8b%e5%8c%96-bYaFSSoHsk\">Linux\u74b0\u5883\u5b89\u88ddMySQL\u9700\u521d\u59cb\u5316<\/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\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\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002\u5728Linux\u74b0\u5883\u4e2d\u5b89\u88ddMySQL\u5f8c\uff0c\u9032\u884c\u521d\u59cb\u5316\u662f\u78ba\u4fdd\u6578\u64da\u5eab\u6b63\u5e38\u904b\u884c\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728Linux\u74b0\u5883\u4e2d\u5b89\u88ddMySQL\u4e26\u9032\u884c\u521d\u59cb\u5316\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql-bYaFSSoHsk\">\u5b89\u88ddMySQL<\/h2>\n<p>\u5728Linux\u7cfb\u7d71\u4e2d\u5b89\u88ddMySQL\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4ee5Ubuntu\u70ba\u4f8b\u7684\u5b89\u88dd\u6b65\u9a5f\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\u6aa2\u67e5MySQL\u670d\u52d9\u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status mysql\n<\/code><\/pre>\n<p>\u5982\u679c\u670d\u52d9\u6b63\u5728\u904b\u884c\uff0c\u5247\u986f\u793a\u7684\u72c0\u614b\u61c9\u70ba\u201cactive (running)\u201d\u3002<\/p>\n<h2 id=\"%e5%88%9d%e5%a7%8b%e5%8c%96mysql-bYaFSSoHsk\">\u521d\u59cb\u5316MySQL<\/h2>\n<p>\u5b89\u88ddMySQL\u5f8c\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u9032\u884c\u521d\u59cb\u5316\u3002\u9019\u4e00\u6b65\u9a5f\u4e3b\u8981\u662f\u8a2d\u7f6e\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u548c\u57fa\u672c\u914d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5MySQL\u5b89\u5168\u6027\u8173\u672c\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>\u9019\u500b\u8173\u672c\u6703\u5f15\u5c0e\u7528\u6236\u5b8c\u6210\u4e00\u7cfb\u5217\u7684\u5b89\u5168\u8a2d\u7f6e\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u8a2d\u7f6eroot\u7528\u6236\u7684\u5bc6\u78bc<\/li>\n<li>\u522a\u9664\u533f\u540d\u7528\u6236<\/li>\n<li>\u7981\u6b62root\u9060\u7a0b\u767b\u9304<\/li>\n<li>\u522a\u9664\u6e2c\u8a66\u6578\u64da\u5eab<\/li>\n<li>\u91cd\u65b0\u52a0\u8f09\u6b0a\u9650\u8868<\/li>\n<\/ul>\n<p>\u6839\u64da\u63d0\u793a\uff0c\u9010\u6b65\u5b8c\u6210\u9019\u4e9b\u8a2d\u7f6e\uff0c\u4ee5\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u3002<\/p>\n<h2 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-bYaFSSoHsk\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236<\/h2>\n<p>\u5b8c\u6210\u521d\u59cb\u5316\u5f8c\uff0c\u53ef\u4ee5\u958b\u59cb\u5275\u5efa\u6578\u64da\u5eab\u548c\u7528\u6236\u3002\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u9304\u5230MySQL\uff1a<\/p>\n<pre><code>sudo mysql -u root -p\n<\/code><\/pre>\n<p>\u8f38\u5165\u5bc6\u78bc\u5f8c\uff0c\u9032\u5165MySQL\u547d\u4ee4\u884c\u754c\u9762\u3002\u63a5\u4e0b\u4f86\uff0c\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>CREATE DATABASE my_database;\n<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u5275\u5efa\u4e00\u500b\u7528\u6236\u4e26\u6388\u4e88\u5176\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u8a2a\u554f\u6b0a\u9650\uff1a<\/p>\n<pre><code>CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n<p>\u9019\u6a23\u5c31\u5b8c\u6210\u4e86\u6578\u64da\u5eab\u548c\u7528\u6236\u7684\u5275\u5efa\u3002<\/p>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%80%a3%e6%8e%a5-bYaFSSoHsk\">\u6e2c\u8a66\u9023\u63a5<\/h2>\n<p>\u6700\u5f8c\uff0c\u70ba\u4e86\u78ba\u4fdd\u4e00\u5207\u6b63\u5e38\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b0\u5275\u5efa\u7684\u7528\u6236\u9032\u884c\u9023\u63a5\u6e2c\u8a66\uff1a<\/p>\n<pre><code>mysql -u my_user -p my_database\n<\/code><\/pre>\n<p>\u8f38\u5165\u5bc6\u78bc\u5f8c\uff0c\u5982\u679c\u6210\u529f\u9032\u5165\u6578\u64da\u5eab\uff0c\u5247\u8868\u793a\u521d\u59cb\u5316\u904e\u7a0b\u5df2\u7d93\u5b8c\u6210\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-bYaFSSoHsk\">\u7e3d\u7d50<\/h2>\n<p>\u5728Linux\u74b0\u5883\u4e2d\u5b89\u88ddMySQL\u4e26\u9032\u884c\u521d\u59cb\u5316\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u548c\u6b63\u5e38\u904b\u884c\u3002\u7121\u8ad6\u662f\u958b\u767c\u65b0\u61c9\u7528\u9084\u662f\u7ba1\u7406\u73fe\u6709\u7cfb\u7d71\uff0cMySQL\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\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\u670d\u52d9\uff0c\u9019\u6a23\u53ef\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u9748\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to initialize MySQL installation in a Linux environment for optimal performance and security. Step-by-step guide included.<\/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-62285","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62285","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=62285"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62285\/revisions"}],"predecessor-version":[{"id":62286,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62285\/revisions\/62286"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=62285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=62285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=62285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}