{"id":142,"date":"2019-04-03T11:10:32","date_gmt":"2019-04-03T07:10:32","guid":{"rendered":"http:\/\/kidds.co.za\/?p=142"},"modified":"2020-06-03T12:29:26","modified_gmt":"2020-06-03T08:29:26","slug":"reset-a-mysql-root-password","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2019\/04\/03\/reset-a-mysql-root-password\/","title":{"rendered":"Reset a MySQL root password"},"content":{"rendered":"\n<p>Use the following steps to reset a MySQL root password by using the command line interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"stop-the-mysql-service\">Stop the MySQL service<\/h3>\n\n\n\n<p>(Ubuntu and Debian) Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/mysql stop\n<\/code><\/pre>\n\n\n\n<p>(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/mysqld stop\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"start-mysql-without-a-password\">Start MySQL without a password<\/h3>\n\n\n\n<p>Run the following command. The ampersand (&amp;) at the end of the command is required.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysqld_safe --skip-grant-tables &amp;\nfor mysql 8\nsudo mysqld --skip-grant-tables --shared-memory &amp;\n\nIf the server does not start it is because it cannot create its pid file. Follow below to fix.\nsudo mkdir \/var\/run\/mysqld\/\nsudo chown mysql:mysql \/var\/run\/mysqld\/\nThen run the top command again to start the server.\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"connect-to-mysql\">Connect to MySQL<\/h3>\n\n\n\n<p>Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -uroot\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"set-a-new-mysql-root-password\">Set a new MySQL root password<\/h3>\n\n\n\n<p>Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use mysql;\n\nupdate user set authentication_string=PASSWORD(\"mynewpassword\") where User='root';\nupdate user set plugin=\"mysql_native_password\" where User='root';\nflush privileges;\nquit\n\nFor mysql 8\nmysql 8 needs more, we will set a blank password for root, restart the server normally then issue the normal change password query.\n\nUPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';\n\nDo not forget to run the normal change password command for mysql 8 after you restart the server normally.\nThis is the command once logged in as root but remember only once logged in to the normal running server or you will get errors.\n\nALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"stop-and-start-the-mysql-service\">Stop and start the MySQL service<\/h3>\n\n\n\n<p>(Ubuntu and Debian) Run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/mysql stop\n...\nsudo \/etc\/init.d\/mysql start\n<\/code><\/pre>\n\n\n\n<p>(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/etc\/init.d\/mysqld stop\n...\nsudo \/etc\/init.d\/mysqld start\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"log-in-to-the-database\">Log in to the database<\/h3>\n\n\n\n<p>Test the new password by logging in to the database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>Enter your new password when prompted.<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use the following steps to reset a MySQL root password by using the command line interface. Stop the MySQL service (Ubuntu and Debian) Run the following command: (CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command: Start MySQL without a password Run the following command. The ampersand (&amp;) at the end of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-db","category-linux"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":6,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/142\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}