{"id":363,"date":"2016-09-06T19:05:58","date_gmt":"2016-09-06T11:05:58","guid":{"rendered":"http:\/\/play.datalude.com\/blog\/?p=363"},"modified":"2020-03-18T15:51:46","modified_gmt":"2020-03-18T07:51:46","slug":"mysql-root-password-reset-for-systemd","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2016\/09\/mysql-root-password-reset-for-systemd\/","title":{"rendered":"mysql root password reset &#8230; for systemd"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">There are a lot of posts around telling you how to update mysql root password. \"Simple!,\" they cry, \"just start mysqld_safe, and use mysqladmin &#8230;\" But wait, what's that? You don't HAVE mysqld_safe? Well the chances are,&nbsp; you've got one of these new fangled systemd systems, where everything is ass backwards.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then you went and tried to run mysqld as root didn't you? That didn't work either. Read on &#8230;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">So the trick is, you don't need mysqld_safe any more, as you can control the &#8211;skip-grant-tables directly from systemctl. First of all you can take a look at what's in the systemctl environment with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl show-environment<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I just had LANG and PATH settings in mine, and nothing to do with MYSQL, so it was no problem to use set-environment to add the skip-grant-tables option. I was doing this on a live server, and didn't want the downtime, so I put it all in a script, below, but if you can afford some downtime, then you can type the commands one by one. When you get to the mysql bit, you can put in your chosen password: my script just replaces the root password with the word 'blank', and then I went and changed it manually when the database was back up and running again.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash \n# MySQL Root Password Reset Script. For Systemd systems. \n\nSYSTEMCTL=$(which systemctl)\n\n# If you're typing manually start here, replacing $SYSTEMCTL with \/usr\/bin\/systemctl or whatever it is on your system\n$SYSTEMCTL stop mysqld.service\n$SYSTEMCTL set-environment MYSQLD_OPTS=\"--skip-grant-tables \"\n$SYSTEMCTL start mysqld.service\n\nmysql -u root -e \"UPDATE mysql.user SET authentication_string = PASSWORD('blank') WHERE User = 'root' AND Host = 'localhost';\"\n\n$SYSTEMCTL stop mysqld.service \n$SYSTEMCTL unset-environment MYSQLD_OPTS \n$SYSTEMCTL start mysqld.service \n\n# This just to check its running OK\n$SYSTEMCTL status mysqld.service \n\necho \"Try logging in with 'mysql -uroot -p' and the password 'blank'\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A few footnotes.<br>\n1) On my system the <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/validate-password-options-variables.html\" target=\"_blank\" rel=\"noopener noreferrer\">validate password options<\/a> module was running, and at a quite high level, so I had to include Upper case, lower case, and special characters in the password before it was accepted.<br>\n2) If you're copying the script wholesale make sure you clean up all the inverted commas and quote-marks that WordPress may have destroyed.<br>\n3) This was mysql 5.7 on Centos. So the SQL is \"SET authentication_string\" not \"SET password\" any more. Because they like changing things.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a lot of posts around telling you how to update mysql root password. \"Simple!,\" they cry, \"just start mysqld_safe, and use mysqladmin &#8230;\" But wait, what's that? You don't HAVE mysqld_safe? Well the chances are,&nbsp; you've got one of these new fangled systemd systems, where everything is ass backwards. Then you went and &#8230; <a title=\"mysql root password reset &#8230; for systemd\" class=\"read-more\" href=\"https:\/\/play.datalude.com\/blog\/2016\/09\/mysql-root-password-reset-for-systemd\/\" aria-label=\"Read more about mysql root password reset &#8230; for systemd\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-it"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":0,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/363\/revisions"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}