{"id":698,"date":"2012-01-31T20:48:57","date_gmt":"2012-02-01T03:48:57","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=698"},"modified":"2017-10-18T12:34:57","modified_gmt":"2017-10-18T19:34:57","slug":"how-to-reset-mysql-root-password-when-forgotten","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=698","title":{"rendered":"How to reset MySQL root password, when forgotten.."},"content":{"rendered":"<p>This was bit more challenging in CentOS 7:<\/p>\n<p>I couldn&#8217;t get MySQL\/MariaDB to start up in safe mode.  I kept getting the following no matter what options I tried:<\/p>\n<blockquote><p>170324 15:23:36 [ERROR] Can&#8217;t find messagefile &#8216;\/share\/mysql\/errmsg.sys&#8217;<br \/>\n170324 15:23:36 [ERROR] Aborting<\/p><\/blockquote>\n<p>I know this is probably overkill, but I finally decided I would just pass mysqld_safe, fully qualified, all the same parameters as I noticed when I had mysql running as well as the &#8211;init-file to reset the root password I forgot:<\/p>\n<blockquote><p>\/usr\/bin\/mysqld_safe &#8211;basedir=\/usr &#8211;datadir=\/var\/lib\/mysql &#8211;plugin-dir=\/usr\/lib64\/mysql\/plugin &#8211;user=mysql &#8211;init-file=\/tmp\/a.sql &#8211;log-error=\/var\/lib\/mysql\/hostname.err &#8211;pid-file=\/var\/lib\/mysql\/hostname.pid &#8211;skip-grant-tables<\/p><\/blockquote>\n<p>I probably just needed to basedir option.<\/p>\n<p>I checked this and this all I needed in CentOS 7:<\/p>\n<blockquote><p>mysqld_safe &#8211;basedir=\/usr &#8211;skip-grant-tables &#038;<\/p><\/blockquote>\n<p>These are the steps used to reset the root password in MySQL running on a linux system.  In my case, it was CentOS 5.6.<\/p>\n<p>Login as root.<\/p>\n<p>Check to see what user ID MySQL is running under.  In CentOS\/RedHat it is mysql.<\/p>\n<p># su &#8211; mysql<\/p>\n<p>Stop MySQL if it is currently running.<\/p>\n<p># kill `cat \/var\/run\/mysqld\/mysqld.pid`<\/p>\n<p>or, as root:<\/p>\n<p># service mysqld stop<\/p>\n<p>Create a temporary sql script containing the following:<\/p>\n<p># vi tmp.sql<br \/>\nUPDATE mysql.user SET Password=PASSWORD(&#8216;<em>newpassword<\/em>&#8216;)  WHERE User=&#8217;root&#8217;;<br \/>\nFLUSH PRIVILEGES;<\/p>\n<p>Start up MySQL in safe mode using the initialization script you just created:<\/p>\n<p># mysqld_safe &#8211;init-file=tmp.sql &#038;<\/p>\n<p>Test the new password:<\/p>\n<p># mysql -u root -p <em>newpassword<\/em><br \/>\nmysql><\/p>\n<p>As root: &#038;<\/p>\n<p># service mysqld stop<br \/>\n# service mysqld start<\/p>\n<p>Process used in Ubuntu 12.04.<br \/>\nHere is the process in Ubunutu:<\/p>\n<p># service mysql stop<br \/>\n# mysqld &#8211;skip-grant-tables &#038;<br \/>\n# mysql -u root mysql<br \/>\nmysql> UPDATE user SET Password=PASSWORD(&#8216;newpassword&#8217;) WHERE User=&#8217;root&#8217;;<br \/>\nmysql> FLUSH PRIVILEGES;<br \/>\nmysql> quit<br \/>\n# service mysql start<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was bit more challenging in CentOS 7: I couldn&#8217;t get MySQL\/MariaDB to start up in safe mode. I kept getting the following no matter what options I tried: 170324 15:23:36 [ERROR] Can&#8217;t find messagefile &#8216;\/share\/mysql\/errmsg.sys&#8217; 170324 15:23:36 [ERROR] Aborting I know this is probably overkill, but I finally decided I would just pass mysqld_safe, [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[48,248,249,136,369],"class_list":["post-698","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-linux","tag-mysql","tag-password","tag-reset","tag-safe"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=698"}],"version-history":[{"count":5,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":1606,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/698\/revisions\/1606"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}