{"id":43172,"date":"2024-10-04T19:51:32","date_gmt":"2024-10-04T11:51:32","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43172\/"},"modified":"2024-10-04T19:51:32","modified_gmt":"2024-10-04T11:51:32","slug":"centos-7-%e4%b8%8a%e5%ae%89%e8%a3%9d-mysql-%e4%b8%a6%e9%85%8d%e7%bd%ae%e9%81%a0%e7%a8%8b%e5%ae%89%e5%85%a8%e9%80%a3%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43172\/","title":{"rendered":"CentOS 7 \u4e0a\u5b89\u88dd MySQL \u4e26\u914d\u7f6e\u9060\u7a0b\u5b89\u5168\u9023\u63a5"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%8a%e5%ae%89%e8%a3%9d-mysql-%e4%b8%a6%e9%85%8d%e7%bd%ae%e9%81%a0%e7%a8%8b%e5%ae%89%e5%85%a8%e9%80%a3%e6%8e%a5-HKJNiCDkal\">CentOS 7 \u4e0a\u5b89\u88dd MySQL \u4e26\u914d\u7f6e\u9060\u7a0b\u5b89\u5168\u9023\u63a5<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0cMySQL \u4f5c\u70ba\u4e00\u500b\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\u672c\u6587\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd MySQL \u4e26\u914d\u7f6e\u9060\u7a0b\u5b89\u5168\u9023\u63a5\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u53ef\u8a2a\u554f\u6027\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mysql-HKJNiCDkal\">\u5b89\u88dd MySQL<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u7684 CentOS 7 \u7cfb\u7d71\u662f\u6700\u65b0\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo yum update<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd MySQL \u7684\u5b98\u65b9\u5b58\u5132\u5eab\u3002\u9996\u5148\uff0c\u4e0b\u8f09 MySQL \u7684 RPM \u5305\uff1a<\/p>\n<pre><code>wget https:\/\/dev.mysql.com\/get\/mysql57-community-release-el7-11.noarch.rpm<\/code><\/pre>\n<p>\u7136\u5f8c\u5b89\u88dd RPM \u5305\uff1a<\/p>\n<pre><code>sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd MySQL\uff1a<\/p>\n<pre><code>sudo yum install mysql-community-server<\/code><\/pre>\n<h2 id=\"%e5%95%9f%e5%8b%95-mysql-%e6%9c%8d%e5%8b%99-HKJNiCDkal\">\u555f\u52d5 MySQL \u670d\u52d9<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u555f\u52d5 MySQL \u670d\u52d9\u4e26\u8a2d\u7f6e\u5176\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start mysqld\nsudo systemctl enable mysqld<\/code><\/pre>\n<p>\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0cMySQL \u6703\u81ea\u52d5\u751f\u6210\u4e00\u500b\u81e8\u6642\u7684 root \u5bc6\u78bc\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u8a72\u5bc6\u78bc\uff1a<\/p>\n<pre><code>sudo grep 'temporary password' \/var\/log\/mysqld.log<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-mysql-HKJNiCDkal\">\u914d\u7f6e MySQL<\/h2>\n<p>\u4f7f\u7528\u81e8\u6642\u5bc6\u78bc\u767b\u9304 MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u5728\u63d0\u793a\u6642\u8f38\u5165\u81e8\u6642\u5bc6\u78bc\u3002\u767b\u9304\u5f8c\uff0c\u5efa\u8b70\u60a8\u7acb\u5373\u66f4\u6539 root \u5bc6\u78bc\uff1a<\/p>\n<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED BY '\u65b0\u5bc6\u78bc';<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae%e9%81%a0%e7%a8%8b%e8%a8%aa%e5%95%8f-HKJNiCDkal\">\u914d\u7f6e\u9060\u7a0b\u8a2a\u554f<\/h2>\n<p>\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0cMySQL \u53ea\u5141\u8a31\u672c\u5730\u8a2a\u554f\u3002\u8981\u5141\u8a31\u9060\u7a0b\u8a2a\u554f\uff0c\u60a8\u9700\u8981\u4fee\u6539 MySQL \u7684\u914d\u7f6e\u6587\u4ef6\u3002\u6253\u958b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/my.cnf<\/code><\/pre>\n<p>\u5728 [mysqld] \u90e8\u5206\u4e2d\uff0c\u6dfb\u52a0\u6216\u4fee\u6539\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>bind-address = 0.0.0.0<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u5141\u8a31\u4f86\u81ea\u4efb\u4f55 IP \u5730\u5740\u7684\u9023\u63a5\u3002\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u5f8c\uff0c\u91cd\u555f MySQL \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart mysqld<\/code><\/pre>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e9%81%a0%e7%a8%8b%e7%94%a8%e6%88%b6-HKJNiCDkal\">\u5275\u5efa\u9060\u7a0b\u7528\u6236<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u7528\u65bc\u9060\u7a0b\u8a2a\u554f\u7684 MySQL \u7528\u6236\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa\u7528\u6236\u4e26\u6388\u4e88\u6b0a\u9650\uff1a<\/p>\n<pre><code>CREATE USER '\u65b0\u7528\u6236'@'%' IDENTIFIED BY '\u7528\u6236\u5bc6\u78bc';\nGRANT ALL PRIVILEGES ON *.* TO '\u65b0\u7528\u6236'@'%' WITH GRANT OPTION;<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>FLUSH PRIVILEGES;<\/code><\/pre>\n<h2 id=\"%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-HKJNiCDkal\">\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u5982\u679c\u60a8\u7684 CentOS \u7cfb\u7d71\u555f\u7528\u4e86\u9632\u706b\u7246\uff0c\u60a8\u9700\u8981\u5141\u8a31 MySQL \u7684\u9ed8\u8a8d\u7aef\u53e3\uff083306\uff09\u901a\u904e\u9632\u706b\u7246\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u958b\u653e\u7aef\u53e3\uff1a<\/p>\n<pre><code>sudo firewall-cmd --zone=public --add-port=3306\/tcp --permanent\nsudo firewall-cmd --reload<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%81%a0%e7%a8%8b%e9%80%a3%e6%8e%a5-HKJNiCDkal\">\u6e2c\u8a66\u9060\u7a0b\u9023\u63a5<\/h2>\n<p>\u5728\u9060\u7a0b\u8a08\u7b97\u6a5f\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e2c\u8a66\u9023\u63a5\uff1a<\/p>\n<pre><code>mysql -u \u65b0\u7528\u6236 -h \u4f3a\u670d\u5668IP -p<\/code><\/pre>\n<p>\u8f38\u5165\u7528\u6236\u5bc6\u78bc\u5f8c\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u6210\u529f\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-HKJNiCDkal\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd MySQL \u4e26\u914d\u7f6e\u9060\u7a0b\u5b89\u5168\u9023\u63a5\u3002\u901a\u904e\u9075\u5faa\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u5b89\u5168\u6027\u548c\u53ef\u8a2a\u554f\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88dd MySQL\uff0c\u4e26\u914d\u7f6e\u5b89\u5168\u7684\u9060\u7a0b\u9023\u63a5\uff0c\u78ba\u4fdd\u6578\u64da\u5b89\u5168\u8207\u9ad8\u6548\u8a2a\u554f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43172","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43172","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=43172"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43172\/revisions"}],"predecessor-version":[{"id":43173,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43172\/revisions\/43173"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}