{"id":1561,"date":"2020-04-27T22:30:00","date_gmt":"2020-04-27T14:30:00","guid":{"rendered":"https:\/\/www.yumefx.com\/?p=1561"},"modified":"2021-03-02T22:40:19","modified_gmt":"2021-03-02T14:40:19","slug":"centos%e9%85%8d%e7%bd%aemysql","status":"publish","type":"post","link":"https:\/\/www.yumefx.com\/?p=1561","title":{"rendered":"Centos\u914d\u7f6emysql"},"content":{"rendered":"\n<p>\u8bb0\u5f55\u4e00\u4e0bCentOS7\u4e0a\u90e8\u7f72mysql\u6570\u636e\u5e93\u7684\u6d41\u7a0b\u3002<\/p>\n<p>\u00a0<\/p>\n<h1 style=\"text-align: center;\">\u5b89\u88c5&amp;\u542f\u52a8<\/h1>\n<p>\u6ce8\u610f\u7248\u672c\uff0c\u6211\u8fd8\u662f\u6bd4\u8f83\u60f3\u5c1d\u8bd5\u65b0\u7684\u7248\u672c\u3002<\/p>\n\n\n\n<pre>\n<span>#\u4e0b\u8f7dyum\u6e90\u7684\u5b89\u88c5\u5305 <\/span>\n<span>yum localinstall https:\/\/repo.mysql.com\/\/mysql80-community-release-el7-1.noarch.rpm<\/span>\n<span>#\u5b89\u88c5<\/span>\n<span>yum install mysql-community-server<\/span>\n<\/pre>\n\n\n\n<p>\u4f7f\u7528<code>systemctl<\/code>\u547d\u4ee4\u542f\u52a8<code>mysql<\/code>\u3002<\/p>\n\n\n\n<pre>\n<span>systemctl start mysqld<\/span>\n<\/pre>\n\n\n\n<p>\u67e5\u770bmysql\u72b6\u6001<\/p>\n\n\n\n<pre>\n<span>systemctl status mysqld<\/span>\n<\/pre>\n\n\n\n<p><img loading=\"lazy\" class=\"size-full wp-image-1562 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2020\/04\/mysql_01.png\" alt=\"\" width=\"671\" height=\"229\" \/><\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u66f4\u6539\u521d\u59cb\u5bc6\u7801<\/h1>\n<p>mysql\u7b2c\u4e00\u6b21\u542f\u52a8\u5b8c\u6bd5\u540e\u4f1a\u81ea\u52a8\u521b\u5efa<code>root<\/code>\u8d26\u6237\u548c\u968f\u673a\u5bc6\u7801\uff0c\u67e5\u770b\u521d\u59cb\u5bc6\u7801\u7684\u65b9\u5f0f\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre>\n<span>grep &#x27;temporary password&#x27; \/var\/log\/mysqld.log<\/span>\n<\/pre>\n\n\n\n<p><img loading=\"lazy\" class=\"size-full wp-image-1563 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2020\/04\/mysql_02.png\" alt=\"\" width=\"853\" height=\"46\" \/><\/p>\n<p>\u62ff\u5230\u521d\u59cb\u5bc6\u7801\u540e\uff0c\u767b\u5f55\u8fdb\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<pre>\n<span>mysql -uroot -p<\/span>\n<\/pre>\n\n\n\n<p>\u7136\u540e\u8f93\u5165\u521d\u59cb\u5bc6\u7801\uff0c\u8fdb\u5165\u6570\u636e\u5e93\u64cd\u4f5c\u754c\u9762\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n\n\n\n<pre>\n<span>mysql&gt; ALTER USER &#x27;root&#x27;@&#x27;localhost&#x27; IDENTIFIED BY &#x27;\u65b0\u5bc6\u7801&#x27;;<\/span>\n<\/pre>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u5bc6\u7801\u4e0d\u80fd\u592a\u7b80\u5355\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u5bc6\u7801\u8bbe\u7f6e\u5931\u8d25\u3002\u6700\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5237\u65b0\u6743\u9650\u914d\u7f6e\u3002<\/p>\n\n\n\n<pre>\n<span>mysql> flush privileges;<\/span>\n<\/pre>\n\n\n\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u914d\u7f6e\u8fdc\u7a0b\u8bbf\u95ee<\/h1>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u6570\u636e\u5e93\u53ea\u5141\u8bb8\u672c\u5730\u8bbf\u95ee\uff0c\u4f8b\u5982<code>root@localhost<\/code>\u6216\u8005<code>root@127.0.0.1<\/code>\u3002<\/p>\n<p>\u914d\u7f6e\u8fdc\u7a0b\u8bbf\u95ee\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u7b2c\u4e00\u79cd\u662f\u8fd0\u884c\u547d\u4ee4\u3002<\/p>\n\n\n\n<pre>\n<span>mysql&gt; GRANT ALL PRIVILEGES ON *.* TO &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED BY &#x27;\u5bc6\u7801&#x27; WITH GRANT OPTION;<\/span>\n<span>mysql&gt; FLUSH PRIVILEGES;<\/span>\n<\/pre>\n\n\n\n<p>\u7b2c\u4e8c\u79cd\u662f\u66f4\u65b0\u6570\u636e\u5e93\u6570\u636e\u65b9\u5f0f\u3002<\/p>\n\n\n\n<pre>\n<span>mysql&gt; use mysql;<\/span>\n<span>mysql&gt; update user set host = &#x27;%&#x27; where user = &#x27;root&#x27;;<\/span>\n<span>mysql&gt; FLUSH PRIVILEGES;<\/span>\n<\/pre>\n\n\n\n<p>\u672c\u8d28\u4e0a\u5c31\u662f\u66f4\u6539<code>mysql<\/code>\u6570\u636e\u5e93\u4e2d<code>user<\/code>\u8868\u7684<code>host<\/code>\u9879\uff0c\u9ed8\u8ba4<code>localhost<\/code>\u4e3a\u53ea\u5141\u8bb8\u672c\u5730\u767b\u5f55\uff0c<code>%<\/code>\u610f\u601d\u4e3a\u5141\u8bb8\u4efb\u610f\u5730\u70b9\u8fdc\u7a0b\u767b\u9646\uff0c\u5982\u679c\u66f4\u6539\u4e3a\u4e00\u4e2a\u5177\u4f53\u7684<code>IP<\/code>\uff0c\u5219\u53ea\u80fd\u5728\u90a3\u4e2aIP\u4e0a\u767b\u5f55\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">Navicat\u8fde\u63a5\u95ee\u9898<\/h1>\n<p>Navicat\u662f\u4e00\u4e2a\u5f88\u597d\u7528\u7684\u6570\u636e\u5e93\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u4f46\u662f\u5728\u8fde\u63a5mysql8\u7248\u672c\u7684\u6570\u636e\u5e93\u65f6\u4f1a\u62a5\u9519\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-1564 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2020\/04\/mysql_03.png\" alt=\"\" width=\"976\" height=\"679\" \/><\/p>\n<p>\u539f\u56e0\u662fmysql8 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\u52a0\u5bc6\u89c4\u5219\u662fmysql_native_password,\u800c\u5728mysql8\u4e4b\u540e,\u52a0\u5bc6\u89c4\u5219\u662fcaching_sha2_password\u3002<\/p>\n<p>\u89e3\u51b3\u95ee\u9898\u65b9\u6cd5\u6709\u4e24\u79cd,\u4e00\u79cd\u662f\u5347\u7ea7navicat\u9a71\u52a8,\u4e00\u79cd\u662f\u628amysql\u7528\u6237\u767b\u5f55\u5bc6\u7801\u52a0\u5bc6\u89c4\u5219\u8fd8\u539f\u6210mysql_native_password\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u6bd4\u8f83\u5e38\u7528\uff0c\u547d\u4ee4\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre>\n<span>#\u4fee\u6539\u52a0\u5bc6\u89c4\u5219<\/span>\n<span>mysql&gt; ALTER USER &#x27;root&#x27;@&#x27;localhost&#x27; IDENTIFIED WITH mysql_native_password BY &#x27;password&#x27;;  <\/span>\n<span>#\u66f4\u65b0\u7528\u6237\u5bc6\u7801<\/span>\n<span>mysql&gt; ALTER USER &#x27;root&#x27;@&#x27;localhost&#x27; IDENTIFIED BY &#x27;password&#x27; PASSWORD EXPIRE NEVER;  <\/span>\n<span>#\u5237\u65b0\u6743\u9650<\/span>\n<span>mysql&gt; FLUSH PRIVILEGES;  <\/span>\n<\/pre>\n\n\n\n<p>\u6ce8\u610f\u8fd9\u91cc<code>\u2018root\u2019@'localhost'<\/code>\uff0c\u5982\u679c\u524d\u9762\u914d\u7f6e\u4e86\u8fdc\u7a0b\u8bbf\u95ee\uff0c\u90a3\u4e48\u5c31\u5f97\u6309\u7167\u8fdc\u7a0b\u8bbf\u95ee\u65b9\u5f0f\u8fdb\u884c\u66f4\u6539\uff0c\u65e0\u9650\u5236\u8fdc\u7a0b\u65f6\u8fd9\u91cc\u662f<code>'root'@'%'<\/code>\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u7528\u6237\u64cd\u4f5c<\/h1>\n<h3>\u521b\u5efa\u7528\u6237<\/h3>\n\n\n\n<pre>\n<span>mysql&gt; CREATE USER &#x27;username&#x27;@&#x27;host&#x27; IDENTIFIED BY &#x27;password&#x27;;<\/span>\n<\/pre>\n\n\n\n<ul>\n<li>username\uff1a\u521b\u5efa\u7684\u7528\u6237\u540d<\/li>\n<li>host\uff1a\u6307\u5b9a\u8be5\u7528\u6237\u5728\u54ea\u4e2a\u4e3b\u673a\u4e0a\u53ef\u4ee5\u767b\u9646\uff0c\u5982\u679c\u662f\u672c\u5730\u7528\u6237\u53ef\u7528localhost\uff0c\u5982\u679c\u60f3\u8ba9\u8be5\u7528\u6237\u53ef\u4ee5\u4ece\u4efb\u610f\u8fdc\u7a0b\u4e3b\u673a\u767b\u9646\uff0c\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26%<\/li>\n<li>password\uff1a\u8be5\u7528\u6237\u7684\u767b\u9646\u5bc6\u7801\uff0c\u5bc6\u7801\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u5982\u679c\u4e3a\u7a7a\u5219\u8be5\u7528\u6237\u53ef\u4ee5\u4e0d\u9700\u8981\u5bc6\u7801\u767b\u9646\u670d\u52a1\u5668<\/li>\n<\/ul>\n<h3>\u00a0<\/h3>\n<h3>\u7528\u6237\u6388\u6743<\/h3>\n\n\n\n<pre>\n<span>mysql&gt; GRANT privileges ON databasename.tablename TO &#x27;username&#x27;@&#x27;host&#x27;<\/span>\n<\/pre>\n\n\n\n<ul>\n<li>privileges\uff1a\u7528\u6237\u7684\u64cd\u4f5c\u6743\u9650\uff0c\u5982<code>SELECT<\/code>\uff08\u53ea\u8bfb\uff09\uff0c<code>INSERT<\/code>\uff0c<code>UPDATE<\/code>\u7b49\uff0c\u5982\u679c\u8981\u6388\u4e88\u6240\u6709\u6743\u9650\u5219\u4f7f\u7528<code>ALL<\/code><\/li>\n<li>databasename\uff1a\u6570\u636e\u5e93\u540d<\/li>\n<li>tablename\uff1a\u8868\u540d\uff0c\u5982\u679c\u8981\u6388\u4e88\u8be5\u7528\u6237\u5bf9\u6240\u6709\u6570\u636e\u5e93\u548c\u8868\u7684\u76f8\u5e94\u64cd\u4f5c\u6743\u9650\u5219\u53ef\u7528<code>*<\/code>\u8868\u793a\uff0c\u5982<code>*.*<\/code><\/li>\n<\/ul>\n<p>\u7528\u4ee5\u4e0a\u547d\u4ee4\u6388\u6743\u7684\u7528\u6237\u4e0d\u80fd\u7ed9\u5176\u5b83\u7528\u6237\u6388\u6743\uff0c\u5982\u679c\u60f3\u8ba9\u8be5\u7528\u6237\u53ef\u4ee5\u6388\u6743\uff0c\u7528\u4ee5\u4e0b\u547d\u4ee4:<\/p>\n\n\n\n<pre>\n<span>mysql&gt; GRANT privileges ON databasename.tablename TO &#x27;username&#x27;@&#x27;host&#x27; WITH GRANT OPTION;<\/span>\n<\/pre>\n\n\n\n<h3>\u00a0<\/h3>\n<h3>\u8bbe\u7f6e\u4e0e\u66f4\u6539\u7528\u6237\u5bc6\u7801<\/h3>\n\n\n\n<pre>\n<span>mysql&gt; SET PASSWORD FOR &#x27;username&#x27;@&#x27;host&#x27; = PASSWORD(&#x27;newpassword&#x27;);<\/span>\n<\/pre>\n\n\n\n<p>\u5982\u679c\u662f\u5f53\u524d\u767b\u9646\u7528\u6237\u7528:<\/p>\n\n\n\n<pre>\n<span>mysql&gt; SET PASSWORD = PASSWORD(&quot;newpassword&quot;);<\/span>\n<\/pre>\n\n\n\n<h3>\u00a0<\/h3>\n<h3>\u64a4\u9500\u7528\u6237\u6743\u9650<\/h3>\n\n\n\n<pre>\n<span>mysql&gt; REVOKE privilege ON databasename.tablename FROM &#x27;username&#x27;@&#x27;host&#x27;;<\/span>\n<\/pre>\n\n\n\n<h3>\u00a0<\/h3>\n<h3>\u5220\u9664\u7528\u6237<\/h3>\n\n\n\n<pre>\n<span>mysql&gt; DROP USER &#x27;username&#x27;@&#x27;host&#x27;;<\/span>\n<\/pre>\n\n\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u90a3\u4f60\u4e3a\u4ec0\u4e48\u521b\u7acb\u5b97\u6559\uff1f<\/p>\n<p>\u6211\u53ea\u521b\u9020\u4eba\u7c7b\uff0c\u662f\u4eba\u7c7b\u53c8\u521b\u7acb\u5b97\u6559\u548c\u79cd\u65cf\uff0c\u5e74\u590d\u4e00\u5e74\u7684\u6d41\u4f20\u4e0b\u6765\uff0c\u662f\u56e0\u4e3a\u4eba\u4eec\u9700\u8981\u5b83\u3002<\/p>\n<p>\u4f46\u4eba\u4eec\u5e94\u8be5\u6452\u5f03\u8bf8\u5982\u6b64\u7c7b\u7684\u5b97\u6559\u3002<\/p>\n<p>\u5343\u4e07\u4e0d\u8981\u5265\u593a\u522b\u4eba\u7684\u4fe1\u4ef0\uff0c\u4f60\u4e00\u65e6\u5c06\u5176\u5265\u593a\uff0c\u4ed6\u4eec\u5c31\u4f1a\u8f6c\u800c\u628a\u4f60\u5f53\u6210\u5b97\u6559\u6765\u4fe1\u5949\u3002<\/p>\n<p style=\"text-align: right;\">\u2014\u2014\u300a\u5076\u6ef4\u795e\u554a\u300b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb0\u5f55\u4e00\u4e0bCentOS7\u4e0a\u90e8\u7f72mysql\u6570\u636e\u5e93\u7684\u6d41\u7a0b\u3002 \u00a0 \u5b89\u88c5&amp;\u542f\u52a8 \u6ce8\u610f\u7248\u672c\uff0c\u6211\u8fd8\u662f\u6bd4\u8f83\u60f3\u5c1d\u8bd5\u65b0\u7684\u7248 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1567,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,4,6],"tags":[41,48,14],"_links":{"self":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/1561"}],"collection":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1561"}],"version-history":[{"count":0,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/1561\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/media\/1567"}],"wp:attachment":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}