编程小贴士

给你的编程提供小点子


正确重置MySQL密码

谁都不想弄丢家门钥匙,但不管多么小心,时间长了,这样的事情总会发生几次。MySQL密码也是一样,把它写在文档上不太安全,记在脑子里又难免会忘记。

如果你忘记了MySQL密码,如何重置它呢?

下面是错误答案:

首先停止MySQL服务,然后使用skip-grant-tables参数启动它:

shell> /etc/init.d/mysql stop
shell> mysqld_safe –skip-grant-tables &

此时无需授权就可以进入到MySQL命令行,使用SQL重置MySQL密码:

UPDATE mysql.user SET Password=PASSWORD(‘…’) WHERE User=’…’ AND Host= ‘…';
FLUSH PRIVILEGES;

为什么说它是错误答案?因为在单纯使用skip-grant-tables参数启动服务后,除非数据库服务器屏蔽了外网访问,否则除了自己,其它别有用心的人也可能访问数据库,尽管重置密码所需的时间很短,但俗话说不怕贼偷就怕贼惦记着,任何纰漏都可能酿成大祸。

下面是正确答案:

关键点是:在使用skip-grant-tables参数的同时,还要加上skip-networking参数:

shell> mysqld_safe –skip-grant-tables –skip-networking &

接着使用SQL重置密码后,记得去掉skip-networking,以正常方式重启MySQL服务:

shell> /etc/init.d/mysqld restart

上面的方法需要重启两次服务,实际上还能更优雅一点,重启一次即可:

首先需要把用到的SQL语句保存到一个文本文件里(/path/to/init/file):

UPDATE mysql.user SET Password=PASSWORD(‘…’) WHERE User=’…’ AND Host= ‘…';
FLUSH PRIVILEGES;

接着使用init-file参数启动MySQL服务,

shell> /etc/init.d/mysql stop
shell> mysqld_safe –init-file=/path/to/init/file &

此时,密码就已经重置了,最后别忘了删除文件内容,免得泄露密码。

提示:本文用到的参数都是通过命令行mysqld_safe传递的,实际上也可以通过my.cnf。

132 Responses to “ 正确重置MySQL密码 ”

  1. chocopie说道:

    dBoDWM I was suggested this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my problem. You are wonderful! Thanks!

  2. wonderful points altogether, you simply received a logo new reader. What might you suggest in regards to your submit that you made some days ago? Any positive?

  3. xem tu vi说道:

    You ave made some good points there. I looked on the web to learn more about the issue and found most people will go along with your views on this website.

  4. coloring page说道:

    Some genuinely choice blog posts on this website , bookmarked.

  5. Lung Health说道:

    Wow! This blog looks just like my old one! It as on a entirely different subject but it has pretty much the same page layout and design. Wonderful choice of colors!

  6. very nice put up, i definitely love this website, keep on it

  7. This is a topic that as near to my heart Cheers! Where are your contact details though?

  8. I was recommended this website by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my trouble. You are wonderful! Thanks!

  9. Di Outdoor说道:

    So pleased to possess discovered this submit.. Seriously useful perception, appreciate your posting.. Appreciate the posting you given.. indeed, analysis is paying off.

  10. Click to read说道:

    I value the blog article.Really looking forward to read more. Cool.

  11. hamptonbay说道:

    Usually I do not learn post on blogs, but I would like to say that this write-up very forced me to check out and do it! Your writing style has been amazed me. Thanks, quite nice post.

  12. Looking forward to reading more. Great article.Really looking forward to read more. Keep writing.

  13. There is noticeably a bundle to learn about this. I assume you made sure nice points in features also.

  14. web site说道:

    There as a lot of people that I think would really appreciate your content. Please let me know. Many thanks

  15. w88 world说道:

    I truly appreciate this article.Really looking forward to read more. Awesome.

  16. That is a great point to bring up. Thanks for the post.

  17. Nice blog here! Also your site loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as fast as yours lol

  18. bo kit arduino说道:

    wonderful post, very informative. I wonder why the other specialists of this sector don at realize this. You must proceed your writing. I am sure, you ave a great readers a base already!

  19. Woking taxi说道:

    Wow, amazing blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is great, as well as the content!

  20. Really appreciate you sharing this blog article.Much thanks again. Much obliged.

  21. You made some good points there. I looked on the internet for the issue and found most individuals will approve with your blog.

  22. Thanks so much for the blog article.Thanks Again. Awesome.

  23. This is one awesome article post.Much thanks again.

  24. The Lost Ways说道:

    Really appreciate you sharing this blog post.Really looking forward to read more. Will read on

  25. Muchos Gracias for your article post.Thanks Again. Keep writing.

  26. Wow! Thank you! I permanently needed to write on my blog something like that. Can I implement a part of your post to my blog?

  27. see this here说道:

    This is one awesome post.Really looking forward to read more. Great.

  28. Nwokolo说道:

    Wow, great blog post.Thanks Again. Awesome.

  29. mo hinh mut xop说道:

    What as up, this weekend is pleasant for me, as this moment i am reading this wonderful informative piece of writing here at my home.

  30. klm coupon code说道:

    You have made some decent points there. I checked on the internet for more info about the issue and found most individuals will go along with your views on this site.

  31. You can certainly see your skills in the paintings you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. Always follow your heart.

  32. You ave made some really good points there. I checked on the web for additional information about the issue and found most people will go along with your views on this web site.

  33. Woah! I am really enjoying the template/theme of this blog. It as simple, yet effective.

  34. Landfill说道:

    It as nearly impossible to find well-informed people in this particular subject, however, you sound like you know what you are talking about! Thanks

  35. Your personal stuffs outstanding. At all times handle it up!

  36. phu kien cho meo说道:

    You have mentioned very interesting points ! ps decent site. Become addicted to constant and never-ending self improvement. by Anthony D aAngelo.

  37. That is an when i was a kid, i really enjoyed going up and down on water slides, it is a very enjoyable experience.

  38. more info说道:

    Loving the info on this website , you have done outstanding job on the blog posts.

  39. adidas nmd r1说道:

    I wish to convey my love for your kindness in support of visitors who really need help on that area of interest. Your personal dedication to passing the solution along turned out to be rather valuable and has consistently encouraged girls like me to arrive at their endeavors. Your amazing informative facts means a whole lot to me and far more to my mates. Regards; from everyone of us.

  40. Im obliged for the post.Really looking forward to read more. Great.

  41. viral marketing说道:

    There are definitely plenty of details like that to take into consideration. That is a nice point to deliver.

  42. more info说道:

    What as up everyone, it as my first visit at this web page, and piece of writing is actually fruitful designed for me, keep up posting such posts.

  43. I think this internet site holds some very great info for everyone .

  44. Ia??a?аАа’аАТ‚аЂ ve recently started a site, the information you provide on this site has helped me tremendously. Thanks for all of your time & work.

  45. We stumbled over here coming from a different web address and thought I may as well check things out. I like what I see so i am just following you. Look forward to looking at your web page repeatedly.

  46. giay da nam说道:

    Very nice write-up. I absolutely love this site. Thanks!

  47. Giay nam说道:

    You have made some decent points there. I looked on the internet for more information about the issue and found most people will go with your views on this site.

  48. Thanks so much for the article.Really looking forward to read more. Much obliged.

  49. Im grateful for the blog post.Really thank you! Great.

  50. Vs model说道:

    Im obliged for the blog article.Really looking forward to read more. Fantastic.

  51. rating说道:

    the time to read or take a look at the content material or websites we ave linked to below the

  52. stella说道:

    Wow! This can be one particular of the most beneficial blogs We ave ever arrive across on this subject. Actually Excellent. I am also an expert in this topic therefore I can understand your hard work.

  53. I really liked your blog.Much thanks again. Keep writing.

  54. Investment tips说道:

    tips on how to lose weight fast WALSH | ENDORA

  55. Hosting说道:

    I value the blog post.Much thanks again. Much obliged.

  56. Just Browsing While I was surfing yesterday I saw a excellent post concerning

  57. xrumer ??????30????????????????5??????????????? | ????????

  58. Crochet poncho说道:

    Usually My spouse and i don at post upon web sites, but I may wish to claim this particular post actually forced myself to achieve this. Very great submit!

  59. Tejidos说道:

    I was suggested this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are amazing! Thanks!

  60. Arctic Circle说道:

    Really appreciate you sharing this post. Cool.

  61. local说道:

    I truly appreciate this blog post.Really thank you! Awesome.

  62. Waec expo说道:

    regarding this website and at the moment this time I am

  63. School news说道:

    You may have some true insight. Why not hold some kind of contest for the readers?

  64. Thanks a lot for the blog post. Really Cool.

  65. This is very interesting, You are a very skilled blogger. I ave joined your feed and look forward to seeking more of your wonderful post. Also, I have shared your web site in my social networks!

  66. click here说道:

    This is a good tip particularly to those new to the blogosphere. Short but very accurate info Many thanks for sharing this one. A must read post!

  67. ItaаАа’б‚Т€ТšаЂаŒаАа’б‚Т€ТžаБТžs tremendous weblog, I desire to be like you

  68. wonderful issues altogether, you just received a logo new reader. What may you suggest in regards to your submit that you just made some days ago? Any positive?

  69. of course, research is paying off. I enjoy you sharing your point of view.. Great thoughts you have here.. I value you discussing your point of view..

  70. Open heaven说道:

    It is actually a good and helpful piece of info. I am glad that you choose to shared this beneficial info with us. Please maintain us informed like this. Thank you for sharing.

  71. Kandace说道:

    of him as nobody else know such designated about my trouble.

  72. tm objection说道:

    Thanks so much for the blog article.Really looking forward to read more. Great.

  73. Apple Reparatur说道:

    Usually I do not read post on blogs, but I wish to say that this write-up very pressured me to try and do it! Your writing style has been amazed me. Thank you, very great post.

  74. Really informative article post.Thanks Again. Really Great.

  75. running off the screen in Ie. I am not sure if this is a formatting issue or something to do with browser compatibility but I figured I ad post to let

  76. cris urzua说道:

    This very blog is definitely cool and diverting. I have chosen many interesting advices out of it. I ad love to come back every once in a while. Thanks a bunch!

  77. Many thanks for sharing this fine piece. Very interesting ideas! (as always, btw)

  78. You have made some good points there. I checked on the web for more information about the issue and found most individuals will go along with your views on this website.

  79. tips说道:

    Utterly written articles , thanks for entropy.

  80. Of course, what a magnificent site and informative posts, I surely will bookmark your blog.All the Best!

  81. Thanks again for the blog.Really thank you! Really Great.

  82. find out more说道:

    Utterly pent content material , appreciate it for selective information.

  83. baby budgeting说道:

    I value the blog post.Really looking forward to read more. Much obliged.

  84. This is one awesome blog.Really looking forward to read more. Great.

  85. pool builders说道:

    I think this is a real great blog post.Really looking forward to read more. Really Cool.

  86. Major thanks for the blog.Really thank you! Awesome.

  87. wow, awesome post.Really thank you! Will read on

  88. I really liked your article.Really thank you! Really Great.

  89. Really informative blog article.Really looking forward to read more. Really Cool.

  90. Wow, fantastic blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is great, as well as the content!

  91. Vanda说道:

    You have made some decent points there. I checked on the internet for more information about the issue and found most people will go along with your views on this web site.

  92. know more说道:

    out the entire thing without having side-effects , folks could take a signal.

  93. more details说道:

    I truly appreciate this article.Really thank you! Great.

  94. guest post说道:

    wonderful post, very informative. I wonder why the other specialists of this sector do not notice this. You should continue your writing. I am confident, you have a great readers a base already!

  95. read more说道:

    Really appreciate you sharing this article post.Really looking forward to read more. Much obliged.

  96. Major thankies for the blog article.Much thanks again. Cool.

  97. Thanks-a-mundo for the article post.Really thank you! Really Great.

  98. you can check说道:

    You made some decent points there. I looked on the net for more information about the issue and found most people will go along with your views on this website.

  99. Major thanks for the blog article.Much thanks again. Really Cool.

  100. Thanks-a-mundo for the post.Much thanks again. Fantastic.

  101. Wohh exactly what I was looking for, appreciate it for posting.

  102. twitter说道:

    You got a very excellent website, Glad I noticed it through yahoo.

  103. for more info说道:

    Your current article usually have got a lot of really up to date info. Where do you come up with this? Just stating you are very imaginative. Thanks again

  104. miller electric说道:

    This is a topic that as close to my heart Many thanks! Exactly where are your contact details though?

  105. It is pretty worth enough for me. In my view, if all

  106. ads说道:

    Just article, We Just article, We liked its style and content. I discovered this blog on Yahoo and also have now additional it to my personal bookmarks. I all be certain to visit once again quickly.

  107. It is actually a great and helpful piece of information. I am glad that you simply shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

  108. find more here说道:

    Thank you, I have just been searching for info about this subject for ages and yours is the greatest I have discovered so far. But, what about the conclusion? Are you sure about the source?

  109. go to说道:

    Yes. It should work. If it doesn at send us an email.

  110. Im obliged for the article.Really thank you! Really Great.

  111. I truly appreciate this article post.Really looking forward to read more. Fantastic.

  112. There is noticeably a lot to identify about this. I believe you made certain good points in features also.

  113. caratulas CD说道:

    You got a very excellent website, Gladiolus I observed it through yahoo.

  114. the net. Disgrace on Google for not positioning this submit upper!

  115. click说道:

    Im thankful for the article post.Really thank you! Great.

  116. casino说道:

    Incredible points. Sound arguments. Keep up the amazing spirit.

  117. Superb read, I just passed this onto a friend who was doing a little study on that. And he really bought me lunch because I found it for him smile So let

  118. buat akun pb说道:

    Usually I do not read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, very nice article.

  119. check here说道:

    Im thankful for the blog.Much thanks again. Great.

  120. go there说道:

    Wow, superb blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is great, as well as the content!

  121. Way cool! Some extremely valid points! I appreciate you penning this post and also the rest of the website is extremely good.

  122. That as some inspirational stuff. Never knew that opinions might be this varied. Thanks for all the enthusiasm to supply such helpful information here.

  123. Hijab说道:

    Thanks a bunch for sharing this with all of us you really know what you are talking about! Bookmarked. Please also visit my website =). We could have a link exchange arrangement between us!

  124. lawyer miami fl说道:

    Major thankies for the blog article.Really looking forward to read more. Fantastic.

  125. Passion in one as true talent is impressive. Writers today usually have little passion about what they write, but you are a unique and great writer. I am glad to see that writers like you exist.

  126. my portfolio说道:

    This excellent website definitely has all the information and facts I needed abo

  127. click here说道:

    Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is magnificent, let alone the content!

  128. sunday说道:

    Utterly written subject matter, thanks for selective information.

  129. seem to be running off the screen in Opera.

  130. You ought to acquire at the really the very least two minutes when you could possibly be brushing your tooth.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>