{"id":897,"date":"2018-07-08T12:28:29","date_gmt":"2018-07-08T04:28:29","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=897"},"modified":"2018-07-08T15:45:59","modified_gmt":"2018-07-08T07:45:59","slug":"linux%e4%b8%8bmysql-5-6%e5%bf%98%e8%ae%b0root%e5%af%86%e7%a0%81%ef%bc%8c%e9%87%8d%e7%bd%aeroot%e5%af%86%e7%a0%81%e8%af%a6%e7%bb%86%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=897","title":{"rendered":"linux\u4e0bmysql-5.6\u5fd8\u8bb0root\u5bc6\u7801\uff0c\u91cd\u7f6eroot\u5bc6\u7801\u8be6\u7ec6\u8fc7\u7a0b"},"content":{"rendered":"<p>\u5728linux\u5e73\u53f0\u4e0b\u4f7f\u7528mysql\u8fc7\u7a0b\u4e2d\u5fd8\u8bb0\u4e86root\u5bc6\u7801\uff0c\u5bf9\u4e8e\u8fd0\u7ef4\u548cDBA\u6765\u8bb2\u90fd\u662f\u4e00\u4ef6\u5934\u75bc\u7684\u4e8b\u60c5\uff0c\u4e0b\u9762\u6765\u8bb2\u89e3\u4e0b\u600e\u4e48\u8fdb\u884c\u91cd\u7f6emysql\u6570\u636e\u5e93root \u5bc6\u7801\uff1a<\/p>\n<p>1\u3001\u9996\u5148\u505c\u6b62mysql\u670d\u52a1\u8fdb\u7a0b\uff1a<\/p>\n<p><span class=\"cnblogs_code\">1\u00a0service mysqld stop<\/span><\/p>\n<p>\u7136\u540e\u7f16\u8f91mysql\u7684\u914d\u7f6e\u6587\u4ef6my.cnf<\/p>\n<div class=\"cnblogs_code\">\n<pre>1 vim \/etc\/my.cnf<\/pre>\n<\/div>\n<p>\u627e\u5230 [mysqld]\u8fd9\u4e2a\u6a21\u5757\uff1a<\/p>\n<p>\u5728\u6700\u540e\u9762\u6dfb\u52a0\u4e00\u6bb5\u4ee3\u7801<\/p>\n<div class=\"cnblogs_code\">\n<pre>1 skip-grant-tables   ##\u5ffd\u7565mysql\u6743\u9650\u95ee\u9898\uff0c\u76f4\u63a5\u767b\u5f55<\/pre>\n<\/div>\n<p>\u7136\u540e\u4fdd\u5b58 :wq!\u9000\u51fa<\/p>\n<p>\u542f\u52a8mysql\u670d\u52a1\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1 service mysqld start<\/pre>\n<\/div>\n<p>\u76f4\u63a5\u8fdb\u5165mysql\u6570\u636e\u5e93\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<pre> 1 Starting MySQL. SUCCESS! \r\n 2 [root@web1 ~]# mysql\r\n 3 Welcome to the MySQL monitor.  Commands end with ; or \\g.\r\n 4 Your MySQL connection id is 1\r\n 5 Server version: 5.6.34 Source distribution\r\n 6 \r\n 7 Copyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\r\n 8 \r\n 9 Oracle is a registered trademark of Oracle Corporation and\/or its\r\n10 affiliates. Other names may be trademarks of their respective\r\n11 owners.\r\n12 \r\n13 Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n14 \r\n15 mysql&gt;<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>\u4f7f\u7528mysql\u8868\uff0c\u7136\u540e\u8fdb\u884c\u4fee\u6539mysql\u7684root\u5bc6\u7801\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<pre><\/pre>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<pre> 1 mysql&gt; use mysql; ##\u4f7f\u7528mysql\u6570\u636e\u5e93\r\n 2 Reading table information for completion of table and column names\r\n 3 You can turn off this feature to get a quicker startup with -A\r\n 4 \r\n 5 Database changed\r\n 6 mysql&gt; update user set password=password(\"123456\") where user=\"root\";##\u66f4\u65b0\u5bc6\u7801\r\n 7 Query OK, 4 rows affected (0.00 sec)\r\n 8 Rows matched: 4  Changed: 4  Warnings: 0\r\n 9 \r\n10 mysql&gt; flush privileges;##\u5237\u65b0\u6743\u9650\r\n11 Query OK, 0 rows affected (0.00 sec)<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<pre> 1 [root@web1 ~]# ps -ef |grep mysql  ##\u663e\u793amysql\u73b0\u6709\u7684\u8fdb\u7a0b\r\n 2 root      56407      1  0 17:50 pts\/0    00:00:00 \/bin\/sh \/usr\/local\/mysql\/bin\/mysqld_safe --datadir=\/data\/mysql --pid-file=\/data\/mysql\/web1.pid\r\n 3 mysql     56533  56407  0 17:50 pts\/0    00:00:00 \/usr\/local\/mysql\/bin\/mysqld --basedir=\/usr\/local\/mysql --datadir=\/data\/mysql --plugin-dir=\/usr\/local\/mysql\/lib\/plugin --user=mysql --log-error=\/data\/mysql\/web1.err --pid-file=\/data\/mysql\/web1.pid\r\n 4 root      56560   1737  0 17:55 pts\/0    00:00:00 grep mysql\r\n 5 [root@web1 ~]# killall mysqld  ##\u5220\u9664mysql\u73b0\u6709\u8fdb\u7a0b\r\n 6 [root@web1 ~]# ps -ef |grep mysql\r\n 7 root      56566   1737  0 17:56 pts\/0    00:00:00 grep mysql\r\n 8 [root@web1 ~]# service mysqld start ##\u91cd\u65b0\u542f\u52a8mysql\u670d\u52a1\r\n 9 Starting MySQL. SUCCESS! \r\n10 [root@web1 ~]# mysql -uroot -p ##\u4f7f\u7528\u65b0\u5bc6\u7801\u767b\u5f55\r\n11 Enter password: \r\n12 Welcome to the MySQL monitor.  Commands end with ; or \\g.\r\n13 Your MySQL connection id is 1\r\n14 Server version: 5.6.34 Source distribution\r\n15 \r\n16 Copyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\r\n17 \r\n18 Oracle is a registered trademark of Oracle Corporation and\/or its\r\n19 affiliates. Other names may be trademarks of their respective\r\n20 owners.\r\n21 \r\n22 Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n23 \r\n24 mysql&gt;<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u5148\u628amysql\u670d\u52a1\u8fdb\u7a0b\u5173\u95ed,\u628a\u6dfb\u52a0\u8fc7\u7684\u8df3\u8fc7\u9a8c\u8bc1\u4fe1\u606f\u5220\u9664\uff0c\u8981\u4e0d\u7136\u5bf9\u6570\u636e\u5e93\u5b89\u5168\u5a01\u80c1\u592a\u5927\uff0c<\/span><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>\u524d\u6bb5\u65f6\u95f4\u5b89\u88c5mysql5.6\u540e\uff0c\u4e60\u60ef\u6027\u7684\u65e0\u5bc6\u7801\u767b\u5f55\uff0c\u4f46\u662f\u63d0\u793a\u8981\u8f93\u5165\u5bc6\u7801<br \/>\n# mysql -u root -p<br \/>\nEnter password:<br \/>\nERROR 1045 (28000): Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217; (using password: NO)<br \/>\n\u597d\u5427\uff0c\u90a3\u6211\u5c31\u5b89\u5168\u6a21\u5f0f\u767b\u5165\uff0c\u4e5f\u5c31\u662f\u5e38\u8bf4\u7684\u7ed5\u8fc7\u5bc6\u7801\u9a8c\u8bc1<br \/>\n# \/etc\/init.d\/mysql stop<br \/>\n# mysqld_safe &#8211;user=mysql &#8211;skip-grant-tables<br \/>\n# mysql -u root mysql<br \/>\nmysql&gt; SET Password=PASSWORD(&#8216;newpassword&#8217;)<br \/>\nmysql&gt; FLUSH PRIVILEGES;<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u4e86\uff0c \u4f46\u662f\u4e3a\u4ec0\u4e48\u548c\u6211\u4e4b\u524d\u5b89\u88c5\u76845.1 \u4e0d\u4e00\u6837\u5462\uff0c\u539f\u6765\u4eceMySQL5.6.8\u5f00\u59cb\uff0cMySQL RPM\u5b89\u88c5\u5305\u7528\u4e86\u66f4\u5b89\u5168\u7684\u5b89\u88c5\u65b9\u5f0f\uff0c\u518d\u4e0d\u662f\u4ee5\u524d\u7684\u5bc6\u7801\u4e3a\u7a7a\u4e86\uff0cmysql\u4f1a\u7ed9root\u8d26\u53f7\u968f\u673a\u5206\u914d\u4e00\u4e2a\u5bc6\u7801\uff0c\u5b89\u88c5MySQL\u540e\uff0croot\u7684\u8fd9\u4e2a\u968f\u673a\u5bc6\u7801\u4f1a\u5199\u5728\u6587\u4ef6\uff1a.mysql_secret\u4e2d\uff0c\u4f46\u8fd9\u4e2a\u5bc6\u7801\u4e0d\u80fd\u505a\u4efb\u4f55\u4e8b\u60c5\uff0c\u53ea\u80fd\u767b\u5f55\u3002<\/p>\n<p>\u7136\u540e\u5fc5\u987b\u66f4\u6539\u5bc6\u7801\u624d\u80fd\u6b63\u5e38\u4f7f\u7528\uff0c\u5982\uff1a<br \/>\nmysql&gt; set password =password(&#8216;123456&#8217;);<br \/>\n\u5237\u65b0\u6743\u9650<br \/>\nmysql&gt; flush privileges;<br \/>\nroot\u8d26\u53f7\u5c31\u6b63\u5e38\u4f7f\u7528\u4e86\u3002<\/p>\n<p>\u5982\u679c\u611f\u5174\u8da3\uff0c\u53ef\u4ee5\u67e5\u770b\u5b98\u65b9\u7684\u89e3\u91ca\uff1a<br \/>\nhttp:\/\/dev.mysql.com\/doc\/refman\/5.6\/en\/linux-installation-rpm.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728linux\u5e73\u53f0\u4e0b\u4f7f\u7528mysql\u8fc7\u7a0b\u4e2d\u5fd8\u8bb0\u4e86root\u5bc6\u7801\uff0c\u5bf9\u4e8e\u8fd0\u7ef4\u548cDBA\u6765\u8bb2\u90fd&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=897\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-897","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=897"}],"version-history":[{"count":4,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/897\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/897\/revisions\/922"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}