{"id":446,"date":"2025-06-14T01:23:00","date_gmt":"2025-06-13T17:23:00","guid":{"rendered":"https:\/\/cn1.club\/?p=446"},"modified":"2026-06-14T16:39:51","modified_gmt":"2026-06-14T08:39:51","slug":"centos7%e5%ae%89%e8%a3%85mariadb%e9%98%bf%e9%87%8c%e4%ba%91%e6%ba%90","status":"publish","type":"post","link":"http:\/\/cn1.club\/?p=446","title":{"rendered":"Centos7\u5b89\u88c5mariadb(\u963f\u91cc\u4e91\u6e90)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"toc-0\">1.\u66f4\u6362\u672c\u5730mariadb\u6e90<\/h2>\n\n\n\n<p>vi \/etc\/yum.repos.d\/MariaDB.repo<\/p>\n\n\n\n<p>\u5c06\u4ee5\u4e0b\u5185\u5bb9\u7c98\u8d34\u8fdb\u53bb,:wq!\u4fdd\u5b58<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&#091;mariadb]\nname = MariaDB\nbaseurl = https:\/\/mirrors.aliyun.com\/mariadb\/yum\/11.4\/centos7-amd64\/\ngpgkey = https:\/\/mirrors.aliyun.com\/mariadb\/yum\/RPM-GPG-KEY-MariaDB\ngpgcheck = 1\nenabled = 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-1\">2.\u6e05\u9664\u7f13\u5b58,\u5b89\u88c5mariadb<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u6e05\u7406\u7f13\u5b58\nsudo yum clean all\n\n# \u91cd\u65b0\u751f\u6210\u7f13\u5b58\nyum makecache\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\">3.\u5b89\u88c5 EPEL \u6269\u5c55\u6e90\uff08\u89e3\u51b3 pv \u5305\u7f3a\u5931\u95ee\u9898\uff09<\/h2>\n\n\n\n<p>CentOS 7 \u5df2\u7ecf\u5728 2024 \u5e74 6 \u6708 30 \u65e5\u6b63\u5f0f\u505c\u6b62\u7ef4\u62a4\uff08EOL\uff09\u3002\u53d7\u6b64\u5f71\u54cd\uff0c\u963f\u91cc\u4e91\u955c\u50cf\u7ad9\uff08mirrors.aliyun.com\uff09\u8fd1\u671f\u5bf9\u76ee\u5f55\u7ed3\u6784\u8fdb\u884c\u4e86\u5927\u8c03\u6574\uff0c\u539f\u5148\u7684 epel-release-latest-7.noarch.rpm \u76f4\u63a5\u4e0b\u8f7d\u94fe\u63a5\u5df2\u7ecf\u88ab\u79fb\u9664\u6216\u5f52\u6863\uff0c\u5bfc\u81f4 YUM \u65e0\u6cd5\u76f4\u63a5\u6253\u5f00\u8be5\u94fe\u63a5\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7 \u624b\u52a8\u7528 vi \u521b\u5efa\u963f\u91cc\u4e91 EPEL \u6e90\u914d\u7f6e\u6587\u4ef6 \u7684\u65b9\u5f0f\u6765\u76f4\u63a5\u7ed5\u8fc7\u5b83<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sudo vi \/etc\/yum.repos.d\/epel.repo<\/code><\/pre>\n\n\n\n<p>\u5c06\u4ee5\u4e0b\u5185\u5bb9\u7c98\u8d34\u81f3\u4e0a\u65b9vi\u4e2d\u5e76\u4fdd\u5b58\u9000\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&#091;epel]\nname=Extra Packages for Enterprise Linux 7 - $basearch\nbaseurl=https:\/\/mirrors.aliyun.com\/epel\/7\/$basearch\nfailovermethod=priority\nenabled=1\ngpgcheck=0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\">4.\u6e05\u7406\u5e76\u5f3a\u5236\u91cd\u6784 YUM \u7f13\u5b58<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u6e05\u7406\u6240\u6709\u7f13\u5b58\u548c\u65e7\u7684\u4e8b\u52a1\u9501\nsudo yum clean all\n\n# \u91cd\u65b0\u751f\u6210\u9ad8\u901f\u7f13\u5b58\nsudo yum makecache<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-4\">5.\u5b89\u88c5 pv \u4f9d\u8d56\u4e0e MariaDB<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sudo yum install -y pv MariaDB-server MariaDB-client<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-5\">6.\u542f\u52a8 MariaDB \u670d\u52a1<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u542f\u52a8\u670d\u52a1\nsudo systemctl start mariadb\n\n# \u68c0\u67e5\u670d\u52a1\u72b6\u6001\nsudo systemctl status mariadb<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-6\">+\u5904\u7406\u95ee\u9898:\u542f\u52a8\u670d\u52a1\u62a5\u9519<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1018\" height=\"490\" src=\"https:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425005-image.png\" alt=\"\" class=\"wp-image-450\" srcset=\"http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425005-image.png 1018w, http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425005-image-300x144.png 300w, http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425005-image-768x370.png 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>CentOS 7 \u7684\u5185\u6838\u7248\u672c\u8fc7\u65e7\uff08\u901a\u5e38\u662f 3.10\uff09\uff0c\u6216\u8005\u662f\u5728\u8f83\u65e7\u7684\u865a\u62df\u5316\u73af\u5883\uff08\u5982\u8001\u7248\u672c\u7684 OpenVZ\u3001Docker \u5bb9\u5668\u6216\u672a\u5f00\u542f\u5bf9\u5e94\u652f\u6301\u7684\u865a\u62df\u673a\uff09\u4e2d\uff0c\u5176 systemd \u65e0\u6cd5\u6b63\u786e\u89e3\u6790\u6216\u652f\u6301\u65b0\u7248 MariaDB \u914d\u7f6e\u6587\u4ef6\u91cc\u5b9a\u4e49\u7684\u67d0\u4e9b\u7279\u6743\uff08AmbientCapabilities\/CapabilityBoundingSet\uff09\uff0c\u4ece\u800c\u5bfc\u81f4\u8fdb\u7a0b\u5728\u521b\u5efa\u521d\u671f\u5c31\u76f4\u63a5\u88ab\u5185\u6838\u62e6\u622a\u5d29\u6e83\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u4f7f\u7528 vi \u4fee\u6539 systemd \u914d\u7f6e,\u7f16\u8f91 MariaDB \u7684\u670d\u52a1\u6587\u4ef6\uff0c\u6ce8\u91ca\u6389\u5f15\u8d77\u517c\u5bb9\u6027\u95ee\u9898\u7684 AmbientCapabilities \u9009\u9879\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sudo systemctl edit mariadb.service<\/code><\/pre>\n\n\n\n<p>\u5199\u5165\u517c\u5bb9\u6027\u914d\u7f6e<br>\u539f\u7406\u89e3\u91ca\uff1a \u8fd9\u91cc\u7684\u8d4b\u503c\u7559\u7a7a\uff0c\u4ee3\u8868\u5728 systemd \u4e2d\u6e05\u9664\u5e76\u7981\u7528\u8be5\u670d\u52a1\u5bf9\u5185\u6838 Capabilities \u7684\u7279\u6b8a\u8981\u6c42\uff0c\u8ba9\u5b83\u9000\u56de\u5230\u4f20\u7edf\u7684 root \u6743\u9650\u6a21\u5f0f\u542f\u52a8\uff0c\u4ece\u800c\u517c\u5bb9 CentOS 7 \u7684\u65e7\u5185\u6838\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&#091;Service]\nAmbientCapabilities=\nCapabilityBoundingSet=<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-7\">7.1\u5237\u65b0\u914d\u7f6e\u5e76\u91cd\u65b0\u542f\u52a8<\/h2>\n\n\n\n<p>\u4fee\u6539\u4e86 systemd \u7684\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u5fc5\u987b\u5237\u65b0\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7136\u540e\u518d\u6b21\u5c1d\u8bd5\u542f\u52a8<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u91cd\u65b0\u52a0\u8f7d systemd \u914d\u7f6e\nsudo systemctl daemon-reload\n\n# \u518d\u6b21\u542f\u52a8 MariaDB\nsudo systemctl start mariadb<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-8\">7.2\u518d\u6b21\u68c0\u67e5\u670d\u52a1\u72b6\u6001<\/h2>\n\n\n\n<p>\u73b0\u5728\u518d\u6b21\u67e5\u770b\u72b6\u6001\uff0c\u5e94\u8be5\u5c31\u80fd\u770b\u5230\u4e45\u8fdd\u7684\u7eff\u8272 active (running) \u4e86<\/p>\n\n\n\n<p>sudo systemctl status mariadb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1025\" height=\"471\" src=\"https:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425468-image.png\" alt=\"\" class=\"wp-image-451\" srcset=\"http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425468-image.png 1025w, http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425468-image-300x138.png 300w, http:\/\/cn1.club\/wp-content\/uploads\/2025\/06\/1781425468-image-768x353.png 768w\" sizes=\"(max-width: 1025px) 100vw, 1025px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-9\">8.\u5b89\u5168\u521d\u59cb\u5316\u914d\u7f6e<\/h2>\n\n\n\n<p>\u4e3a\u4e86\u6570\u636e\u5e93\u7684\u5b89\u5168\uff0c\u5efa\u8bae\u8fd0\u884c MariaDB \u81ea\u5e26\u7684\u5b89\u5168\u521d\u59cb\u5316\u811a\u672c\u3002\u8fd9\u4f1a\u5f15\u5bfc\u4f60\u8bbe\u7f6e root \u5bc6\u7801\u3001\u79fb\u9664\u533f\u540d\u7528\u6237\u3001\u7981\u6b62 root \u8fdc\u7a0b\u767b\u5f55\u7b49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >sudo mariadb-secure-installation<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6e\u8fc7\u7a0b\u4e2d\u7684\u5e38\u89c1\u63d0\u793a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Enter current password for root (enter for none): \u76f4\u63a5\u6309 \u56de\u8f66\uff08\u56e0\u4e3a\u521d\u59cb\u6ca1\u6709\u5bc6\u7801\uff09\u3002<\/li>\n\n\n\n<li>Switch to unix_socket authentication [Y\/n]: \u8f93\u5165 n\u3002<\/li>\n\n\n\n<li>Set root password? [Y\/n]: \u8f93\u5165 y\uff0c\u7136\u540e\u8f93\u5165\u4f60\u60f3\u8bbe\u7f6e\u7684 \u6570\u636e\u5e93 root \u5bc6\u7801\uff08\u8f93\u5165\u65f6\u5c4f\u5e55\u4e0d\u4f1a\u663e\u793a\uff0c\u8f93\u5b8c\u76f4\u63a5\u56de\u8f66\u5373\u53ef\uff09\u3002<\/li>\n\n\n\n<li>Remove anonymous users? [Y\/n]: \u8f93\u5165 y\uff08\u79fb\u9664\u533f\u540d\u7528\u6237\uff09\u3002<\/li>\n\n\n\n<li>Disallow root login remotely? [Y\/n]: \u6839\u636e\u9700\u6c42\u9009\u62e9\uff08\u5982\u679c\u9700\u8981\u8fdc\u7a0b\u8fde\u63a5\u8f93\u5165 n\uff0c\u4e3a\u4e86\u5b89\u5168\u63a8\u8350\u8f93\u5165 y\uff09\u3002<\/li>\n\n\n\n<li>Remove test database and access to it? [Y\/n]: \u8f93\u5165 y\uff08\u5220\u9664\u6d4b\u8bd5\u6570\u636e\u5e93\uff09\u3002<\/li>\n\n\n\n<li>Reload privilege tables now? [Y\/n]: \u8f93\u5165 y\uff08\u5237\u65b0\u6743\u9650\u8868\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-10\">9.\u5c06MariaDB\u670d\u52a1\u8bbe\u4e3a\u5f00\u673a\u81ea\u542f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\nsudo systemctl enable mariadb<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-11\">\u9644:\u5e38\u7528\u547d\u4ee4<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >#\u767b\u5f55\u6570\u636e\u5e93\nmariadb -u root -p\n\n#\u67e5\u770b\u670d\u52a1\u72b6\u6001\nsudo systemctl status mariadb\n\n#\u91cd\u542f\u6570\u636e\u5e93\uff08\u672a\u6765\u4fee\u6539\u4e86\u914d\u7f6e\u6587\u4ef6\u540e\u4f7f\u7528\uff09\nsudo systemctl restart mariadb\n\n#\u505c\u6b62\u6570\u636e\u5e93\nsudo systemctl stop mariadb<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u66f4\u6362\u672c\u5730mariadb\u6e90 vi \/etc\/yum.repos.d\/MariaDB.repo \u5c06\u4ee5\u4e0b\u5185\u5bb9\u7c98\u8d34 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":436,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"class_list":["post-446","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-zheteng"],"_links":{"self":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=446"}],"version-history":[{"count":0,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/446\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/media\/436"}],"wp:attachment":[{"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}