Difference between revisions of "Reset MySQL root password"

From Organic Design wiki
(better process)
(rv)
 
(4 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
}}
 
}}
 
To reset the root password of a MySQL server, first go to a root shell and stop MySQL:
 
To reset the root password of a MySQL server, first go to a root shell and stop MySQL:
{{code|<pre>
+
<source>
/etc/init.d/mysql stop
+
service mysql stop
</pre>}}
+
</source>
  
  
 
Next, run MySQL in safe mode in the background:
 
Next, run MySQL in safe mode in the background:
{{code|<pre>
+
<source>
 
mysqld_safe --skip-grant-tables &
 
mysqld_safe --skip-grant-tables &
</pre>}}
+
</source>
  
  
 
Reset the MySQL root password:
 
Reset the MySQL root password:
{{code|<pre>
+
<source>
 
mysql -u root
 
mysql -u root
use mysql;
+
use mysql
 
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
 
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
 
flush privileges;
 
flush privileges;
 
quit
 
quit
</pre>}}
+
</source>
  
  
 
And restart the MySQL server again:
 
And restart the MySQL server again:
{{code|<pre>
+
<source>
/etc/init.d/mysql restart
+
service mysql start
</pre>}}
+
</source>

Latest revision as of 11:04, 22 July 2019

Procedure.svg Reset MySQL root password
Organic Design procedure

To reset the root password of a MySQL server, first go to a root shell and stop MySQL:

service mysql stop


Next, run MySQL in safe mode in the background:

mysqld_safe --skip-grant-tables &


Reset the MySQL root password:

mysql -u root
use mysql
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit


And restart the MySQL server again:

service mysql start