{"id":4788,"date":"2021-02-25T08:34:11","date_gmt":"2021-02-25T08:34:11","guid":{"rendered":"https:\/\/linuxways.net\/?p=4788"},"modified":"2021-02-25T08:36:48","modified_gmt":"2021-02-25T08:36:48","slug":"how-to-reset-mysql-root-password-on-red-hat-enterprise-linux-8","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/red-hat\/how-to-reset-mysql-root-password-on-red-hat-enterprise-linux-8\/","title":{"rendered":"How to Reset MySQL Root Password on Red Hat Enterprise Linux 8"},"content":{"rendered":"<p>If you have forgotten your MySQL root password on Red Hat Enterprise Linux (RHEL) 8, and you would like to reset it, then you have found the right tutorial. In this guide, you will also learn how to change the password for any other existing MySQL user account.<\/p>\n<h2>Prerequisite<\/h2>\n<p>In order to successfully reset a forgotten MySQL root password, you need to have a Linux user account with sudo privileges on the server running MySQL.<\/p>\n<h2>Reset Forgotten MySQL Root Password<\/h2>\n<p>You would need to go through the following steps to successfully reset your MySQL root password if you have forgotten it.<\/p>\n<ol>\n<li>Stop MySQL<\/li>\n<li>Skip MySQL grant tables<\/li>\n<li>Start MySQL in a minimal environment<\/li>\n<li>Login to MySQL<\/li>\n<li>Alter the MySQL root user<\/li>\n<li>Stop MySQL<\/li>\n<li>Unset Option to skip MySQL grant tables<\/li>\n<li>Start MySQL in a normal environment<\/li>\n<\/ol>\n<h3>Stop MySQL<\/h3>\n<p>The first thing you should do is stop the MySQL server. On RHEL 8, run the following command to stop the MySQL server.<\/p>\n<pre>$ <strong>sudo systemctl stop mysqld<\/strong><\/pre>\n<h3>Skip MySQL grant tables<\/h3>\n<p>The next step is to put the MySQL server in an environment which bypasses the grant tables that store information about user privileges. Run the command below.<\/p>\n<pre>$ <strong>sudo systemctl set-environment MYSQLD_OPTS=\u201d--skip-grant-tables\u201d<\/strong><\/pre>\n<h3>Start MySQL in a minimal environment<\/h3>\n<p>After successfully setting MySQL to skip the grant tables, you may start the service with:<\/p>\n<pre>$<strong> sudo systemctl start mysqld<\/strong><\/pre>\n<h3>Login to MySQL<\/h3>\n<p>Now, you may login to MySQL as follows.<\/p>\n<pre>$<strong> sudo mysql -u root<\/strong><\/pre>\n<p>Once you see the <strong>mysql&gt;<\/strong> prompt as shown in figure 1 below, you know that you have successfully bypassed the password requirement.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"277\" class=\"wp-image-4789\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-388.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-388.png 709w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-388-300x117.png 300w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/strong><\/p>\n<h3>Alter the MySQL root user<\/h3>\n<p>Having successfully logged in to MySQL, you may now alter the root user and update the password.<\/p>\n<p>First, reload the grant tables with the query below.<\/p>\n<pre>mysql&gt; <strong>FLUSH PRIVILEGES;<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"51\" class=\"wp-image-4790\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-389.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-389.png 463w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-389-300x33.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/strong><\/p>\n<p>Next, run the following query to alter the MySQL root user and specify a new password. Replace <strong>NewRootPassw0rd! <\/strong>with your desired password.<\/p>\n<pre>mysql&gt; <strong>ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewRootPassw0rd!'; <\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"65\" class=\"wp-image-4791\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-390.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-390.png 641w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-390-300x30.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/strong><\/p>\n<p>Reload the grant tables and quit MySQL with the next two queries.<\/p>\n<pre>mysql&gt;<strong> FLUSH PRIVILEGES;<\/strong><\/pre>\n<pre>mysql&gt;<strong> QUIT;<\/strong><\/pre>\n<h3>Stop MySQL<\/h3>\n<p>Run the command below to stop MySQL.<\/p>\n<pre>$ <strong>sudo systemctl stop mysqld<\/strong><\/pre>\n<h3>Unset Option to Skip MySQL grant tables<\/h3>\n<p>The next command will unset the option to skip the MySQL grant tables.<\/p>\n<pre>$ <strong>sudo systemctl unset-environment MYSQLD_OPTS<\/strong><\/pre>\n<h3>Start MySQL in a normal environment<\/h3>\n<p>Run the command below to start MySQL again in normal mode.<\/p>\n<pre>$ <strong>sudo systemctl start mysqld<\/strong><\/pre>\n<p>You should now be able to login successfully to MySQL using your new root password as follows.<\/p>\n<pre>$<strong> sudo mysql -u root -p<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"293\" class=\"wp-image-4792\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-391.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-391.png 653w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-391-300x135.png 300w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/strong><\/p>\n<p>Quit MySQL with:<\/p>\n<pre>mysql&gt;<strong> QUIT;<\/strong><\/pre>\n<h2>Change MySQL Root Password<\/h2>\n<p>If you know your MySQL root password and you would like to change it, then simply log in to MySQL as follows.<\/p>\n<pre>$<strong> sudo mysql -u root -p<\/strong><\/pre>\n<p>Once logged in, run the query below to change the password for your MySQL root user. Replace <strong>ChangeRootPassw0rd! <\/strong>with the new password that you would like to use.<\/p>\n<pre>mysql&gt; <strong>ALTER USER 'root'@'localhost' IDENTIFIED BY 'ChangeRootPassw0rd!';<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"95\" class=\"wp-image-4793\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-392.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-392.png 631w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-392-300x45.png 300w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/strong><\/p>\n<p><strong>Note:<\/strong> To change the password for any other MySQL user, just replace <strong>root <\/strong>in the query above with the other user. For example:<\/p>\n<pre>mysql&gt; <strong>ALTER USER 'shola'@'localhost' IDENTIFIED BY 'ChangeSholaPassw0rd!';<\/strong><\/pre>\n<p>After that, reload the grant tables with:<\/p>\n<pre>mysql&gt; <strong>FLUSH PRIVILEGES;<\/strong><\/pre>\n<p>You may now quit MySQL and login again with your new password.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have provided clear instructions to help you successfully reset or change your MySQL root password on Red Hat Enterprise Linux 8. As always, feedback regarding this tutorial is highly welcome.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you have forgotten your MySQL root password on Red Hat Enterprise Linux (RHEL) 8, and you would like to reset it, then you have found the right&hellip;<\/p>","protected":false},"author":28,"featured_media":4794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165],"tags":[27,198],"class_list":["post-4788","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-red-hat","tag-mysql","tag-red-hat-enterprise-linux-8"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4788"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4788\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4794"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}