{"id":812,"date":"2024-09-06T11:26:09","date_gmt":"2024-09-06T03:26:09","guid":{"rendered":"https:\/\/thereisno.top\/?p=812"},"modified":"2024-10-22T15:31:09","modified_gmt":"2024-10-22T07:31:09","slug":"mariadb%e9%a6%96%e6%ac%a1%e7%99%bb%e5%bd%95root%e5%af%86%e7%a0%81%e9%87%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=812","title":{"rendered":"mariadb\u9996\u6b21\u767b\u5f55root\u5bc6\u7801\u91cd\u7f6e"},"content":{"rendered":"\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u65b0\u5b89\u88c5\u7684 mariadb \u7684\u5bc6\u7801\u4e3a\u7a7a\uff0c\u5728shell\u7ec8\u7aef\u76f4\u63a5\u8f93\u5165 mysql \u5c31\u80fd\u767b\u9646\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u521a\u5b89\u88c5\u7b2c\u4e00\u6b21\u4f7f\u7528\uff0c\u8bf7\u4f7f\u7528 mysql_secure_installation \u547d\u4ee4\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p># mysql_secure_installation<\/p>\n\n\n\n<p>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SERVERS IN PRODUCTION USE!&nbsp; PLEASE READ EACH STEP CAREFULLY!<\/p>\n\n\n\n<p>In order to log into MariaDB to secure it, we&#8217;ll need the current<br>password for the root user.&nbsp; If you&#8217;ve just installed MariaDB, and<br>you haven&#8217;t set the root password yet, the password will be blank,<br>so you should just press enter here.<\/p>\n\n\n\n<p>Enter current password for root (enter for none):<br>OK, successfully used password, moving on&#8230;<\/p>\n\n\n\n<p>Setting the root password ensures that nobody can log into the MariaDB<br>root user without the proper authorisation.<\/p>\n\n\n\n<p>Set root password? [Y\/n] y<br>New password:<br>Re-enter new password:<br>Password updated successfully!<br>Reloading privilege tables..<br>&nbsp;&#8230; Success!<\/p>\n\n\n\n<p>By default, a MariaDB installation has an anonymous user, allowing anyone<br>to log into MariaDB without having to have a user account created for<br>them.&nbsp; This is intended only for testing, and to make the installation<br>go a bit smoother.&nbsp; You should remove them before moving into a<br>production environment.<\/p>\n\n\n\n<p>Remove anonymous users? [Y\/n] y<br>&nbsp;&#8230; Success!<\/p>\n\n\n\n<p>Normally, root should only be allowed to connect from &#8216;localhost&#8217;.&nbsp; This<br>ensures that someone cannot guess at the root password from the network.<\/p>\n\n\n\n<p>Disallow root login remotely? [Y\/n] y<br>&nbsp;&#8230; Success!<\/p>\n\n\n\n<p>By default, MariaDB comes with a database named &#8216;test&#8217; that anyone can<br>access.&nbsp; This is also intended only for testing, and should be removed<br>before moving into a production environment.<\/p>\n\n\n\n<p>Remove test database and access to it? [Y\/n] y<br>&nbsp;&#8211; Dropping test database&#8230;<br>&nbsp;&#8230; Success!<br>&nbsp;&#8211; Removing privileges on test database&#8230;<br>&nbsp;&#8230; Success!<\/p>\n\n\n\n<p>Reloading the privilege tables will ensure that all changes made so far<br>will take effect immediately.<\/p>\n\n\n\n<p>Reload privilege tables now? [Y\/n] y<br>&nbsp;&#8230; Success!<\/p>\n\n\n\n<p>Cleaning up&#8230;<\/p>\n\n\n\n<p>All done!&nbsp; If you&#8217;ve completed all of the above steps, your MariaDB<br>installation should now be secure.<\/p>\n\n\n\n<p>Thanks for using MariaDB!<\/p>\n\n\n\n<p><strong>\u8fd9\u91cc\u9488\u5bf9\u7684\u662f\u77e5\u9053<\/strong><strong> root <\/strong><strong>\u5bc6\u7801\uff0c\u800c\u9700\u8981\u4fee\u6539\u7684\u60c5\u51b5\u3002<\/strong><\/p>\n\n\n\n<p>\u4e24\u79cd\u4fee\u6539\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>1\u3001\u76f4\u63a5\u5728shell\u547d\u4ee4\u884c\u4f7f\u7528 mysqladm \u547d\u4ee4\u4fee\u6539\u3002<\/p>\n\n\n\n<p># mysqladmin -uroot -poldpassword password newpassword<\/p>\n\n\n\n<p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u5f0a\u7aef\u5728\u4e8e\u4f1a\u660e\u6587\u663e\u793a\u5bc6\u7801\u3002<\/p>\n\n\n\n<p>2\u3001\u767b\u9646\u6570\u636e\u5e93\u4fee\u6539\u5bc6\u7801\u3002<\/p>\n\n\n\n<p># mysql -uroot -p<\/p>\n\n\n\n<p>2.1 \u66f4\u65b0 mysql \u5e93\u4e2d user \u8868\u7684\u5b57\u6bb5\uff1a<br>MariaDB [(none)]&gt; use mysql;&nbsp;<br>MariaDB [mysql]&gt; UPDATE user SET password=password(&#8216;newpassword&#8217;) WHERE user=&#8217;root&#8217;;&nbsp;<br>MariaDB [mysql]&gt; flush privileges;&nbsp;<br>MariaDB [mysql]&gt; exit;<\/p>\n\n\n\n<p>2.2 \u6216\u8005\uff0c\u4f7f\u7528 set \u6307\u4ee4\u8bbe\u7f6eroot\u5bc6\u7801\uff1a<br>MariaDB [(none)]&gt; SET password for &#8216;root&#8217;@&#8217;localhost&#8217;=password(&#8216;newpassword&#8217;);&nbsp;<br>MariaDB [(none)]&gt; exit;<\/p>\n\n\n\n<p><strong>\u5982\u679c\u662f\u5fd8\u8bb0\u4e86<\/strong><strong> root <\/strong><strong>\u5bc6\u7801\uff0c\u5219\u9700\u8981\u4ee5\u8df3\u8fc7\u6388\u6743\u7684\u65b9\u5f0f\u542f\u52a8<\/strong><strong> mariadb <\/strong><strong>\u6765\u4fee\u6539\u5bc6\u7801\u3002<\/strong><\/p>\n\n\n\n<p>1\u3001\u5148\u505c\u6389\u670d\u52a1\u3002<\/p>\n\n\n\n<p># systemctl stop mariadb<\/p>\n\n\n\n<p>2\u3001\u4f7f\u7528\u8df3\u8fc7\u6388\u6743\u7684\u65b9\u5f0f\u542f\u52a8 mariadb\u3002<\/p>\n\n\n\n<p># mysqld_safe &#8211;skip-grant-tables &amp;<br>[1] 1441<br>[root@centos7 ~]# 170531 02:10:28 mysqld_safe Logging to &#8216;\/var\/log\/mariadb\/mariadb.log&#8217;.<br>170531 02:10:28 mysqld_safe Starting mysqld daemon with databases from \/var\/lib\/mysql<\/p>\n\n\n\n<p># ps -ef | grep 1441<br>root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1441&nbsp;&nbsp; 966&nbsp; 0 02:10 pts\/0&nbsp;&nbsp;&nbsp; 00:00:00 \/bin\/sh \/usr\/bin\/mysqld_safe &#8211;skip-grant-tables<br>mysql&nbsp;&nbsp;&nbsp;&nbsp; 1584&nbsp; 1441&nbsp; 0 02:10 pts\/0&nbsp;&nbsp;&nbsp; 00:00:00 \/usr\/libexec\/mysqld &#8211;basedir=\/usr &#8211;datadir=\/var\/lib\/mysql &#8211;plugin-dir=\/usr\/lib64\/mysql\/plugin &#8211;user=mysql &#8211;skip-grant-tables &#8211;log-error=\/var\/log\/mariadb\/mariadb.log &#8211;pid-file=\/var\/run\/mariadb\/mariadb.pid &#8211;socket=\/var\/lib\/mysql\/mysql.sock<\/p>\n\n\n\n<p>3\u3001\u5f53\u8df3\u8fc7\u6388\u6743\u542f\u52a8\u65f6\uff0c\u53ef\u4ee5\u4e0d\u9700\u8981\u5bc6\u7801\u76f4\u63a5\u767b\u9646\u6570\u636e\u5e93\u3002\u767b\u9646\u66f4\u65b0\u5bc6\u7801\u5373\u53ef\u3002<\/p>\n\n\n\n<p># mysql<br>MariaDB [(none)]&gt; use mysql;&nbsp;<br>MariaDB [mysql]&gt; UPDATE user SET password=password(&#8216;newpassword&#8217;) WHERE user=&#8217;root&#8217;;&nbsp;<br>MariaDB [mysql]&gt; flush privileges;&nbsp;&nbsp;<br>MariaDB [mysql]&gt; exit;<\/p>\n\n\n\n<p>\u66f4\u65b0\u5bc6\u7801\u540e\uff0c\u5728\u8df3\u8fc7\u6388\u6743\u542f\u52a8\u65f6\u4e5f\u4e0d\u80fd\u7a7a\u5bc6\u7801\u76f4\u63a5\u767b\u9646\u4e86\u3002<\/p>\n\n\n\n<p>4\u3001\u5173\u95ed\u8df3\u8fc7\u6388\u6743\u542f\u52a8\u7684\u8fdb\u7a0b\uff1a<\/p>\n\n\n\n<p># kill -9 1441<\/p>\n\n\n\n<p>5\u3001\u6b63\u5e38\u542f\u52a8 mariadb\uff1a<\/p>\n\n\n\n<p># systemctl start mariadb<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u65b0\u5b89\u88c5\u7684 mariadb \u7684\u5bc6\u7801\u4e3a\u7a7a\uff0c\u5728shell\u7ec8\u7aef\u76f4\u63a5\u8f93\u5165 mysql \u5c31\u80fd\u767b\u9646\u6570\u636e\u5e93\u3002 \u5982\u679c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thereisno.top\/?p=812\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cmariadb\u9996\u6b21\u767b\u5f55root\u5bc6\u7801\u91cd\u7f6e\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[148,68],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mariadb","tag-mysql"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=812"}],"version-history":[{"count":2,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":1309,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions\/1309"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}