{"id":1706,"date":"2017-10-31T11:41:56","date_gmt":"2017-10-31T03:41:56","guid":{"rendered":"https:\/\/zoco.me\/?p=28"},"modified":"2017-10-31T11:41:56","modified_gmt":"2017-10-31T03:41:56","slug":"centos7-mariadb-remote-access","status":"publish","type":"post","link":"https:\/\/cloudbool.com\/archive\/centos7-mariadb-remote-access.html","title":{"rendered":"CentOS7\u4e0bMariaDB\u5f00\u542f\u8fdc\u7a0b\u8bbf\u95ee"},"content":{"rendered":"<p>\u4e00\u53f0VPS\u4e0aMariaDB\u6570\u636e\u5e93\u4e2d\u6709\u4e2a\u6570\u636e\u5e93\u5c06\u8fd130G\uff0c\u800c\u6574\u4e2aVPS\u7684\u786c\u76d8\u5374\u53ea\u670940G\uff0c\u4e0d\u7ba1\u662f\u6253\u5305\u5bfc\u51fa\u8fd8\u662f\u5907\u4efd\uff0c\u90fd\u65e0\u6cd5\u76f4\u63a5\u4ee5\u6587\u4ef6\u5f62\u5f0f\u64cd\u4f5c\u5230VPS\u672c\u5730\u786c\u76d8\uff0c\u6ca1\u529e\u6cd5\uff0c\u53ea\u80fd\u60f3\u529e\u6cd5\u901a\u8fc7\u8fdc\u7a0b\u8bbf\u95ee\u7684\u5f62\u5f0f\u5c06\u6570\u636e\u5e93\u5bfc\u51fa\u6765\uff0c\u6bd5\u7adf\u6570\u636e\u624d\u662f\u6700\u91cd\u8981\u7684\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728VPS\u672c\u5730\u786c\u76d8\u8db3\u591f\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4e00\u822c\u90fd\u662f\u76f4\u63a5\u5c06\u6570\u636e\u5e93\u5bfc\u51fa\u7136\u540e\u76f4\u63a5\u6253\u5305\u6210<strong><em>.zip<\/em><\/strong>\u683c\u5f0f\u6587\u4ef6\u518d\u8f6c\u79fb\u5230\u522b\u7684\u670d\u52a1\u5668\uff0c\u4e00\u884c\u547d\u4ee4\u5c31\u80fd\u89e3\u51b3\uff1a<\/p>\n<blockquote><p>\n  mysqldump -u user -p[user_password] [database_name] | gzip > dumpfilename.sql.gz\n<\/p><\/blockquote>\n<p>\u56de\u8f66\u4e4b\u540e\u5c31\u80fd\u5907\u4efd\u6210\u4e00\u4e2a\u5355\u4e2a\u538b\u7f29\u4e4b\u540e\u6587\u4ef6\uff0c\u5907\u4efd\u5b8c\u6210\u4e4b\u540e\u5c31\u80fd\u76f4\u63a5\u590d\u5236\u5230\u4efb\u610f\u5730\u65b9\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u6b21\u56e0\u4e3a\u6570\u636e\u91cf\u592a\u5927\u4e86\uff0c\u5982\u679c\u518d\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u4f1a\u5bfc\u81f4\u6574\u4e2aVPS\u786c\u76d8\u88ab\u7206\uff0c\u6240\u4ee5\u53ea\u80fd\u60f3\u529e\u6cd5\u501f\u52a9\u53e6\u5916\u7684\u670d\u52a1\u5668\u901a\u8fc7\u8fdc\u7a0b\u8fde\u63a5\u7684\u65b9\u5f0f\u5c06\u6570\u636e\u5bfc\u51fa\u53bb\u3002<\/p>\n<p>\u501f\u52a9Google\u641c\u7d22\u4e86\u4e00\u628a\uff0c\u53d1\u73b0\u8fd8\u662fMySQL\u81ea\u5e26\u7684mysqldump\u547d\u4ee4\u6700\u597d\u7528\uff0c\u53ef\u4ee5\u501f\u52a9\u53e6\u5916\u670d\u52a1\u5668\u4e0a\u5b89\u88c5MySQL\u5ba2\u6237\u7aef\uff0c\u7136\u540e\u4f7f\u7528mysqldump\u547d\u4ee4\u8fdc\u7a0b\u8fde\u63a5\u9700\u5907\u4efd\u7684MySQL\u670d\u52a1\u5668\uff0c\u7136\u540e\u901a\u8fc7TCP\u8fde\u63a5\u5c06\u6570\u636e\u5bfc\u51fa\u5230\u65b0\u670d\u52a1\u5668\u3002<\/p>\n<p>\u8fd9\u5c31\u9047\u5230\u4e86\u53e6\u4e00\u4e2a\u95ee\u9898\uff0c\u7531\u4e8eMySQL\u9ed8\u8ba4\u662f\u7981\u6b62\u8fdc\u7a0b\u8bbf\u95ee\u7684\uff0c\u800c\u4e14CentOS7\u81ea\u5e26\u7684\u8fd8\u4e0d\u662f\u4f20\u7edf\u7684MySQL\uff0c\u800c\u662f\u6e90\u81eaMySQL\u7684MariaDB\uff0c\u914d\u7f6e\u8d77\u6765\u7a0d\u6709\u4e0d\u540c\uff0c\u8fd9\u91cc\u4ec5\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n<p>\u6211\u6700\u540e\u9009\u62e9\u7684\u662f\uff0c\u5230DigitalOcean\u5f00\u4e00\u4e2a\u6700\u4f4e\u914d\u7684VPS\uff0c\u7136\u540e\u5f00\u4e00\u4e2a\u5bb9\u91cf\u4e3a50G\u7684Volume\uff0c\u518d\u5230DO\u7684\u8fd9\u4e2aVPS\u4e0a\u5b89\u88c5MariaDB\u76f8\u5173\u8f6f\u4ef6\u5305\uff0c\u8fd9\u6837\u53ef\u4ee5\u901a\u8fc7mysqldump\u8fde\u63a5\u5230\u9700\u5bfc\u51fa\u6570\u636e\u5e93\u7684\u670d\u52a1\u5668\u3002<\/p>\n<p>\u6574\u4e2a\u8fc7\u7a0bDO\u6240\u5728\u7684\u65b0\u670d\u52a1\u5668\u4e0d\u9700\u8981\u8fdb\u884c\u989d\u5916\u7684\u64cd\u4f5c\uff0c\u53ea\u9700\u8981\u5728\u9700\u5bfc\u51fa\u6570\u636e\u5e93\u7684\u670d\u52a1\u5668\u4e0a\u64cd\u4f5c\u5c31\u884c\u3002<\/p>\n<p>\u9ed8\u8ba4CentOS7\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u7684MariaDB\u662f\u652f\u6301\u8fdc\u7a0b\u8fde\u63a5\u7684\uff0c\u53ef\u901a\u8fc7\u4e00\u4e0b\u547d\u4ee4\u67e5\u770bMariaDB\u76d1\u542c\u7684IP\u5730\u5740\u53ca\u76f8\u5173\u7aef\u53e3\uff1a<\/p>\n<blockquote><p>\n  netstat -apn | grep mysql\n<\/p><\/blockquote>\n<p>\u5982\u679c\u8f93\u51fa\u5982\u4e0b\u5185\u5bb9\u5219\u65e0\u9700\u66f4\u6539\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-null\">[root@DOSFO2 volume-sfo2-01]# netstat -apn | grep mysql\ntcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2472\/mysqld\nunix  2      [ ACC ]     STREAM     LISTENING     106927   2472\/mysqld          \/var\/lib\/mysql\/mysql.sock\n<\/code><\/pre>\n<p>\u5982\u679c\u662f\u76d1\u542c\u7684<strong><em>127.0.0.1<\/em><\/strong>\u6216\u8005*** 192.168.<em>.<\/em> ***\u76f8\u5173\u5185\u7f51IP\u6216\u8005\u56de\u73af\u5730\u5740\u5219\u9700\u66f4\u6539MariaDB\u7684\u76d1\u542cIP\u3002<\/p>\n<p>\u9996\u5148\u662f\u66f4\u6539MariaDB\u7684\u76d1\u542c\u5730\u5740\uff0c\u8ba9\u5176\u76d1\u542c\u6574\u4e2a\u4e92\u8054\u7f51\u7684\u8fde\u63a5\uff0c\u8fd9\u6837\u6211\u4eec\u624d\u80fd\u4ece\u5916\u90e8\u670d\u52a1\u5668\u8bbf\u95ee\u8fd9\u53f0\u670d\u52a1\u5668\u7684MariaDB\u670d\u52a1\uff1a<\/p>\n<p>\u5907\u4efd\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<blockquote><p>\n  cp \/etc\/my.cnf{,.bak}\n<\/p><\/blockquote>\n<p>\u66f4\u6539\u6570\u636e\u5e93\u914d\u7f6e\uff1a<\/p>\n<blockquote><p>\n  vim \/etc\/my.cnf\n<\/p><\/blockquote>\n<p>\u5728<strong><em>bind-address = 127.0.0.1<\/em><\/strong>\u8fd9\u4e00\u884c\u524d\u9762\u52a0\u4e0a<strong><em>#<\/em><\/strong>\uff0c\u5c06\u5176\u6ce8\u91ca\u6389\u3002<\/p>\n<p>\u7136\u540e\u91cd\u542fMariaDB\u670d\u52a1\uff1a<\/p>\n<blockquote><p>\n  systemctl restart mariadb\n<\/p><\/blockquote>\n<p>\u518d\u6b21\u7528<strong><em>netstat<\/em><\/strong>\u547d\u4ee4\u67e5\u770bMariaDB\u76d1\u542c\u7684IP\u53ca\u7aef\u53e3\uff0c\u5982\u679c\u662f\u6211\u4e0a\u9762\u5730\u5740\u5219\u53ef\u8fdb\u884c\u4e0b\u4e00\u6b65\u64cd\u4f5c\u3002<\/p>\n<p>\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u6211\u4eec\u4e0d\u5e94\u8be5\u76f4\u63a5\u5141\u8bb8root\u8fdb\u884c\u8fdc\u7a0b\u8bbf\u95ee\uff0c\u6240\u4ee5\u4e0b\u4e00\u6b65\u5c31\u662f\u4e3a\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u4e13\u95e8\u65b0\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7684\u7528\u6237\u5e76\u8d4b\u4e88\u5176\u6743\u9650\u5bf9\u67d0\u4e2a\u6570\u636e\u5e93\u8fdb\u884c\u8fdc\u7a0b\u8bbf\u95ee\uff0c\u4e00\u6837\u7684\uff0c\u4e00\u884c\u547d\u4ee4\u641e\u5b9a\uff1a<\/p>\n<blockquote><p>\n  GRANT ALL PRIVILEGES ON database.* TO database_user@localhost IDENTIFIED BY &#8216;databases_password&#8217;;<br \/>\n  FLUSH PRIVILEGES;\n<\/p><\/blockquote>\n<p>\u6700\u540e\u4e00\u6b65\uff0c\u68c0\u67e5\u9632\u706b\u5899\u3002\u5982\u679c\u5f00\u542f\u4e86\u9632\u706b\u5899\uff0c\u5219\u9700\u653e\u884cMariaDB\u6240\u5728\u76843306\u7aef\u53e3\u3002<\/p>\n<p>\u67e5\u8be23306\u7aef\u53e3\u662f\u5426\u5f00\u653e\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-null\">[root@VPS ~]# firewall-cmd --query-port=3306\/tcp\nno\n<\/code><\/pre>\n<p>\u5982\u679c\u662fno\uff0c\u5219\u653e\u884c\u5e76\u91cd\u65b0\u52a0\u8f7d\u9632\u706b\u5899\u914d\u7f6e\uff1a<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-null\">[root@VPS ~]# firewall-cmd --permanent --add-port=3306\/tcp\nsuccess\n[root@VPS ~]# firewall-cmd --reload\nsuccess\n<\/code><\/pre>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u53ef\u4ee5\u5728\u522b\u7684\u670d\u52a1\u5668\u7528mysqldump\u547d\u4ee4\u8fdc\u7a0b\u8bbf\u95ee\u5e76\u5bfc\u51fa\u5bf9\u5e94\u7684\u6570\u636e\u5e93\u4e86\u3002<\/p>\n<p>\u987a\u4fbf\u8bf4\u4e00\u53e5\uff0c\u7f8e\u5e1d\u670d\u52a1\u5668\u4e92\u76f8\u4e4b\u95f4\u8bbf\u95ee\uff0c\u901f\u5ea6\u771f\u5fc3\u5feb\uff0c\u6211\u5c06\u8fd130G\u5185\u5bb9\uff0c10\u51e0\u5206\u949f\u5c31\u8f6c\u79fb\u597d\u4e86\u3002<\/p>\n<p>\u53e6\u5916\u6ce8\u610f\uff0c\u8f6c\u79fb\u597d\u6570\u636e\u4e4b\u540e\uff0c\u8bb0\u5f97\u628a\u76f8\u5173\u914d\u7f6e\u8fd8\u539f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53f0VPS\u4e0aMariaDB\u6570\u636e\u5e93\u4e2d\u6709\u4e2a\u6570\u636e\u5e93\u5c06\u8fd130G\uff0c\u800c\u6574\u4e2aVPS\u7684\u786c\u76d8\u5374\u53ea\u670940G\uff0c\u4e0d\u7ba1\u662f\u6253\u5305\u5bfc\u51fa\u8fd8\u662f\u5907\u4efd &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/cloudbool.com\/archive\/centos7-mariadb-remote-access.html\"> <span class=\"screen-reader-text\">CentOS7\u4e0bMariaDB\u5f00\u542f\u8fdc\u7a0b\u8bbf\u95ee<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[8],"tags":[17,69],"class_list":["post-1706","post","type-post","status-publish","format-standard","hentry","category-tech","tag-centos","tag-mariadb"],"_links":{"self":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/comments?post=1706"}],"version-history":[{"count":0,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/posts\/1706\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/media?parent=1706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/categories?post=1706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudbool.com\/archive\/wp-json\/wp\/v2\/tags?post=1706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}