Reset a MySQL root password?

wpspeedster

Well-known member
Registered
Joined
May 6, 2016
Messages
120
Points
18
When I was running this command to do some queries in Mysql server on my VPS, it asked root password

Code:
mysql -u root -p
I could not remember its password, I installed and using cPanel.

Does anyone know how to reset a MySQL root password?
 

MooseLucifer

Well-known member
Registered
Joined
May 20, 2016
Messages
149
Points
28
I have already got a post mentioned to how to change password for MySQL on Linux

You can find it here https://forumweb.hosting/13207-how-to-change-password-for-mysql-on-linux.html

If you want to do it quickly to have a new password for MySQL on Linux

I will recommend you run these commands

Step 1

Stop the MySQL service on Ubuntu and Debian

Code:
sudo /etc/init.d/mysql stop
or

For CentOS, Fedora, and Red Hat Enterprise Linux

Code:
sudo /etc/init.d/mysqld stop
If you run right command, it will show this

Shutting down MySQL (Percona Server)........... SUCCESS!
Ok, now you can connect to MySQL by runnning the following command:

Code:
mysql -uroot
When you use the command above, it will show messages like this

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.50-38.0 Percona Server (GPL), Release 38.0, Revision b05b24c

Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Step 2

Set a new MySQL root password

Code:
use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';

flush privileges;

quit
Replace mynewpassword by your password as desired.

You should have messages like this when running commands above

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD("mynewpassword") where User='root';
Query OK, 4 rows affected (0.05 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

mysql> quit
Bye
Restart MySql

Code:
sudo /etc/init.d/mysql start

Now you can login with new password you have just changed.

Hope it helps!
 
Latest Threads
Similar Threads
Replies
5
Views
10,185
Replies
4
Views
7,228
Replies
6
Views
4,388

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top