{"id":45424,"date":"2024-10-06T23:16:16","date_gmt":"2024-10-06T15:16:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45424\/"},"modified":"2024-10-06T23:16:17","modified_gmt":"2024-10-06T15:16:17","slug":"%e5%9c%a8-centos-7-%e4%b8%8a%e9%83%a8%e7%bd%b2-mysql-%e4%b8%bb%e5%be%9e","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45424\/","title":{"rendered":"\u5728 CentOS 7 \u4e0a\u90e8\u7f72 MySQL \u4e3b\u5f9e"},"content":{"rendered":"<h1 id=\"%e5%9c%a8-centos-7-%e4%b8%8a%e9%83%a8%e7%bd%b2-mysql-%e4%b8%bb%e5%be%9e-XsELVsnsZS\">\u5728 CentOS 7 \u4e0a\u90e8\u7f72 MySQL \u4e3b\u5f9e<\/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\u4e3b\u5f9e\u8907\u88fd\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u6578\u64da\u5eab\u67b6\u69cb\uff0c\u80fd\u5920\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u7528\u6027\u548c\u64f4\u5c55\u6027\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u90e8\u7f72 MySQL \u4e3b\u5f9e\u8907\u88fd\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-XsELVsnsZS\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5df2\u7d93\u5b89\u88dd\u4e86 MySQL \u4f3a\u670d\u5668\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd MySQL\uff1a<\/p>\n<pre><code>sudo yum install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 MySQL \u670d\u52d9\u4e26\u8a2d\u7f6e\u5176\u5728\u958b\u6a5f\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start mysqld\nsudo systemctl enable mysqld<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u7372\u53d6 MySQL \u7684\u81e8\u6642\u5bc6\u78bc\uff0c\u9019\u53ef\u4ee5\u5728\u5b89\u88dd\u5f8c\u7684\u65e5\u8a8c\u4e2d\u627e\u5230\uff1a<\/p>\n<pre><code>sudo grep 'temporary password' \/var\/log\/mysqld.log<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae%e4%b8%bb%e4%bc%ba%e6%9c%8d%e5%99%a8-XsELVsnsZS\">\u914d\u7f6e\u4e3b\u4f3a\u670d\u5668<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u914d\u7f6e\u4e3b\u4f3a\u670d\u5668\u3002\u7de8\u8f2f MySQL \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/my.cnf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>[mysqld]\nserver-id=1\nlog-bin=mysql-bin\nbinlog-do-db=your_database_name<\/code><\/pre>\n<p>\u8acb\u5c07 <code>your_database_name<\/code> \u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u8907\u88fd\u7684\u6578\u64da\u5eab\u540d\u7a31\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<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u7528\u65bc\u5f9e\u4f3a\u670d\u5668\u9023\u63a5\u7684\u7528\u6236\u3002\u767b\u9304 MySQL\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u7136\u5f8c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5275\u5efa\u7528\u6236\u4e26\u6388\u4e88\u6b0a\u9650\uff1a<\/p>\n<pre><code>CREATE USER 'replica_user'@'%' IDENTIFIED BY 'your_password';\nGRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%';<\/code><\/pre>\n<p>\u6700\u5f8c\uff0c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u67e5\u770b\u4e3b\u4f3a\u670d\u5668\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u4f4d\u7f6e\uff1a<\/p>\n<pre><code>SHOW MASTER STATUS;<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae%e5%be%9e%e4%bc%ba%e6%9c%8d%e5%99%a8-XsELVsnsZS\">\u914d\u7f6e\u5f9e\u4f3a\u670d\u5668<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u914d\u7f6e\u5f9e\u4f3a\u670d\u5668\u3002\u9996\u5148\uff0c\u7de8\u8f2f\u5f9e\u4f3a\u670d\u5668\u7684 MySQL \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/my.cnf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>[mysqld]\nserver-id=2<\/code><\/pre>\n<p>\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<p>\u7136\u5f8c\uff0c\u767b\u9304\u5230\u5f9e\u4f3a\u670d\u5668\u7684 MySQL\uff0c\u4e26\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u8a2d\u7f6e\u4e3b\u4f3a\u670d\u5668\u7684\u9023\u63a5\uff1a<\/p>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='\u4e3b\u4f3a\u670d\u5668\u7684IP\u5730\u5740',\nMASTER_USER='replica_user',\nMASTER_PASSWORD='your_password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=\u4f4d\u7f6e;<\/code><\/pre>\n<p>\u8acb\u5c07 <code>\u4e3b\u4f3a\u670d\u5668\u7684IP\u5730\u5740<\/code>\u3001<code>your_password<\/code>\u3001<code>mysql-bin.000001<\/code> \u548c <code>\u4f4d\u7f6e<\/code> \u66ff\u63db\u70ba\u76f8\u61c9\u7684\u503c\u3002\u7136\u5f8c\u555f\u52d5\u5f9e\u4f3a\u670d\u5668\u7684\u8907\u88fd\u9032\u7a0b\uff1a<\/p>\n<pre><code>START SLAVE;<\/code><\/pre>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e8%a4%87%e8%a3%bd%e7%8b%80%e6%85%8b-XsELVsnsZS\">\u6aa2\u67e5\u8907\u88fd\u72c0\u614b<\/h2>\n<p>\u8981\u6aa2\u67e5\u5f9e\u4f3a\u670d\u5668\u7684\u8907\u88fd\u72c0\u614b\uff0c\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>SHOW SLAVE STATUSG<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230 <code>Slave_IO_Running<\/code> \u548c <code>Slave_SQL_Running<\/code> \u7684\u503c\u5747\u70ba <code>Yes<\/code>\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XsELVsnsZS\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 7 \u4e0a\u90e8\u7f72 MySQL \u4e3b\u5f9e\u8907\u88fd\u3002\u9019\u7a2e\u67b6\u69cb\u4e0d\u50c5\u80fd\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u5728\u8b80\u53d6\u8acb\u6c42\u589e\u9577\u6642\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684\u670d\u52d9\u3002\u7121\u8ad6\u662f <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\u6211\u5011\u90fd\u80fd\u63d0\u4f9b\u9ad8\u6548\u7684\u652f\u6301\u548c\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 CentOS 7 \u4e0a\u90e8\u7f72 MySQL \u4e3b\u5f9e\uff0c\u5be6\u73fe\u6578\u64da\u9ad8\u53ef\u7528\u6027\u8207\u8ca0\u8f09\u5747\u8861\uff0c\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\u8207\u53ef\u9760\u6027\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-45424","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45424","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=45424"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45424\/revisions"}],"predecessor-version":[{"id":45425,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45424\/revisions\/45425"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}