HomeHowTo › MySQL Root Password Reset

MySQL Root Password Reset

Change The Root Password

If you still know the root password, you can change it using the following command:

mysqladmin -u root -p password

 

Reset The Root Password

If you have forgotten your root password, you can do the following to set a new one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Stop the MySQL daemon with one of these commands
sudo service mysql stop
sudo /etc/init.d/mysql stop

# Start the MySQL daemon in safe mode without rights-management
# Keep in mind, that everyone can log in without a password now
sudo mysqld_safe --skip-grant-tables &

# Log in as root without password
mysql -u root

# Switch into the MySQL database
use mysql;

# Have a look at the current user accounts
SELECT host, user, password FROM user;

# Set a new password for the localhost root user and quit
# If you want to change it for all the root users just omit the host portion
UPDATE user SET password=PASSWORD("newpass") WHERE user="root" AND host="localhost";
quit;

# Stop the safe mode MySQL daemon by killing the corresponding job
jobs
kill %<id>

# Start MySQL in normal mode using one of these commands
sudo service mysql start
sudo /etc/init.d/mysql start

# Log in with the new password
mysql -u root -p

Leave a Comment