Mysql Change Root Password

May 29, 2020 / Nirav Shah

MySQL is a database management system operated under the Open Source software model. It has become a very popular software package for web application software. Like many web services, MySQL has an administrator-level or root password. The root password allows a user to perform all top-level functions in the database.

<!– Begin Table of Contents –>

<script>
var allHeadings;
document.addEventListener(“DOMContentLoaded”, function(event) {
allHeadings = Array.prototype.slice.call(document.querySelectorAll(‘h1, h2, h3, h4, h5, h6’));
});
function jumpTo(title,tag){
allHeadings.forEach(function (singleHeading){
if((singleHeading.localName.toLowerCase().replace(/\u00a0/g, ‘ ‘) == tag.toLowerCase().replace(/\u00a0/g, ‘ ‘) ) && (singleHeading.innerText.toLowerCase().replace(/\u00a0/g, ‘ ‘) == title.toLowerCase().replace(/\u00a0/g, ‘ ‘) )){
singleHeading.scrollIntoView({behavior: ‘smooth’, block: ‘center’});
}
})
}
</script>

<div class=”topic-table-of-contents-container topic-table-of-contents-align-left” style=”position: relative; text-align: left;”>
<div class=”topic-table-of-contents” style=”background-color: rgb(240, 244, 248);
position:relative;
margin-bottom: 40px;
padding: 1.5rem;
border-radius:4px;
display: inline-block;
text-align: left;
width: 300px;”>

<div class=”topic-table-of-contents-label” style=”color:rgb(16, 42, 67) !important; font-weight: bold;
font-size:1rem;
margin-bottom: 1rem;” >
TABLE OF CONTENTS
</div>

<div class=”topic-table-of-contents-line topic-table-of-contents-type-heading topic-table-of-contents-tag-h1″ style=””>
<p onClick=”jumpTo(‘Mysql Change Root Password
Mysql Change Root Password’,’H1′)” style=”color:rgb(16, 42, 67) !important; font-weight: normal;
cursor: pointer;
line-height:normal;
margin-bottom: 1rem !important;
font-size: 1rem;”>
<span style=”color:inherit;
border-bottom: 1px solid rgba(0,0,0,0.1);
line-height: 1.5rem;”>Mysql Change Root Password</span>
</p>
</div>
<div class=”topic-table-of-contents-line topic-table-of-contents-type-heading topic-table-of-contents-tag-h2″ style=”margin-left: 1rem;”>
<p onClick=”jumpTo(‘Steps to reset a MySQL root password’,’H2′)” style=”color:rgb(16, 42, 67) !important; font-weight: normal;
cursor: pointer;
line-height:normal;
margin-bottom: 1rem !important;
font-size: 1rem;”>
<span style=”color:inherit;
border-bottom: 1px solid rgba(0,0,0,0.1);
line-height: 1.5rem;”>Steps to reset a MySQL root password</span>
</p>
</div>
<div class=”topic-table-of-contents-line topic-table-of-contents-type-heading topic-table-of-contents-tag-h2″ style=”margin-left: 1rem;”>
<p onClick=”jumpTo(‘Talk to AWS Certified Consultant’,’H2′)” style=”color:rgb(16, 42, 67) !important; font-weight: normal;
cursor: pointer;
line-height:normal;
margin-bottom: 1rem !important;
font-size: 1rem;”>
<span style=”color:inherit;
border-bottom: 1px solid rgba(0,0,0,0.1);
line-height: 1.5rem;”>Talk to AWS Certified Consultant</span>
</p>
</div>
<div class=”topic-table-of-contents-line topic-table-of-contents-type-heading topic-table-of-contents-tag-h3″ style=”margin-left: 2rem;”>
<p onClick=”jumpTo(‘Patient Management Portal’,’H3′)” style=”color:rgb(16, 42, 67) !important; font-weight: normal;
cursor: pointer;
line-height:normal;
margin-bottom: 1rem !important;
font-size: 1rem;”>
<span style=”color:inherit;
border-bottom: 1px solid rgba(0,0,0,0.1);
line-height: 1.5rem;”>Patient Management Portal</span>
</p>
</div>
<div class=”topic-table-of-contents-line topic-table-of-contents-type-heading topic-table-of-contents-tag-h2″ style=”margin-left: 1rem;”>
<p onClick=”jumpTo(‘Why you need Spa and Salon management software?
Let Us Talk About Your AWS Development Requirements’,’H2′)” style=”color:rgb(16, 42, 67) !important; font-weight: normal;
cursor: pointer;
line-height:normal;
margin-bottom: 1rem !important;
font-size: 1rem;”>
<span style=”color:inherit;
border-bottom: 1px solid rgba(0,0,0,0.1);
line-height: 1.5rem;”>Why you need Spa and Salon management software?
Let Us Talk About Your AWS Development Requirements</span>
</p>
</div>
<a href=”https://www.usetopic.com/wordpress-table-of-contents” style=”color: transparent;”><div style=”position: absolute;
bottom: -28px;
background-image: url(https://www.usetopic.com/wordpress-table-of-contents-powered-by.png);
background-size: contain;
width: 134px;
height: 22px;
background-repeat: no-repeat;
right: 0;
opacity: 0.5;
color: transparent;”>Wordpress Table of Contents by Topic</div></a>
<style>

/* Alignment */
@media screen and (max-width: 600px) {
.topic-table-of-contents-align-float-left {
float: none;
margin-right: 0;
}
.topic-table-of-contents-align-float-left .topic-table-of-contents,
.topic-table-of-contents-align-left .topic-table-of-contents,
.topic-table-of-contents-align-center .topic-table-of-contents{
width: auto;
display: block;
}
}

/* General Styles */

.topic-table-of-contents-type-heading.topic-table-of-contents-line span:hover{
border-bottom: 1px solid rgba(0,0,0,0.4);
}
</style>
</div>
</div>
<!– End Table of Contents –>

If you’ve never set a root password on your MySQL database, you should be able to connect to it. However, this is not a good idea as it means anyone can access your database.

If your database already has a root password, but you lost track of it, this guide will help you reset a Mysql Root password on Linux
<h2></h2>

<a href=”https://www.eternalsoftsolutions.com/aws-services/aws-security-services.php”><button class=”button-40″ role=”button”>AWS SECURITY SERVICES</button></a>

<h2><b>Steps to reset a MySQL root password</b></h2>
<strong>Use the following steps to reset a MySQL root password by using the command line interface.</strong>
<ul class=”listing”>
<li><strong>Step 1: </strong>Stop the MySQL service</li>
</ul>
<pre>$ sudo /etc/init.d/mysql stop</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep1.png” alt=”step-1″ />
<ul class=”listing”>
<li><strong>Step 2: </strong>Run the following command. The ampersand (&amp;) at the end of the command is required.</li>
</ul>
<pre>$ sudo mysqld_safe –skip-grant-tables &amp;</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep2.png” alt=”step-2″ />
<ul class=”listing”>
<li><strong>Step 3: Step 3 ( Optional ) </strong>In some cases, you’ve to create the /var/run/mysqld first:</li>
</ul>
<pre>$ sudo mkdir -v /var/run/mysqld &amp;&amp; sudo chown mysql /var/run/mysqld</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep3.png” alt=”step-3″ />
<ul class=”listing”>
<li><strong>Step 4: </strong>Connect to MySQL</li>
<li>Run the following command:</li>
</ul>
<pre>$ mysql -uroot</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep4.png” alt=”step-4″ />
<ul class=”listing”>
<li><strong>Step 5: </strong>Set a new MySQL root password</li>
<li>Run the following command:</li>
<li>Change the database to mysql</li>
</ul>
<pre>mysql&gt; use mysql;</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep5a.png” alt=”step-5a” />
<ul class=”listing”>
<li>Replace “mynewpassword”
<ul class=”listcircle”>
<li>mysql&gt; update user set authentication_string=PASSWORD(“mynewpassword”) where User=’root’;</li>
</ul>
</li>
</ul>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep5b.png” alt=”step-5b” />
<ul class=”listing”>
<li>
<ul class=”listcircle”>
<li>mysql&gt; flush privileges;</li>
</ul>
</li>
</ul>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep5c.png” alt=”step-5c” />
<ul class=”listing”>
<li>
<ul class=”listcircle”>
<li>mysql&gt; exit</li>
</ul>
</li>
</ul>
<ul class=”listing”>
<li><strong>Step 6: </strong>Stop and start the MySQL service</li>
<li>Stop the mysql service</li>
</ul>
<pre>$ sudo /etc/init.d/mysql stop</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep6a.png” alt=”step-6a” />
<ul class=”listing”>
<li>Start the mysql service</li>
</ul>
<pre>$ sudo /etc/init.d/mysql start</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep6b.png” alt=”step-6b” />
<ul class=”listing”>
<li><strong>Step 7: </strong>Log in to the database</li>
<li>Test the new password by logging in to the database.</li>
</ul>
<pre>$ mysql -u root -p</pre>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep7a.png” alt=”step-7a” />
<ul class=”listing”>
<li>Enter your new password when prompted.</li>
</ul>
<img class=”img-responsive” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2020/05/mysqlstep7b.png” alt=”step-7b” />

<strong>Also read: </strong><a style=”color: #0b5f9e;” href=”https://www.eternalsoftsolutions.com/blog/how-enable-username-password-authentication-for-linux-ec2/”><span style=”font-weight: 400;”>How Enable Username &amp; Password Authentication for Linux EC2</span></a>

&nbsp;

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let’s Talk About Your Needed AWS Infrastructure Management Services

    Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project