SOURCECODEBD.NET

Live Experience

How To Reset MySQL Root Password 

Operating Systems - Ubuntu Linux  
 
The first thing you need to do is login to your server as root. 
 
 
#/etc/init.d/mysql stop
 
You need to restart again
 
#/etc/init.d/mysql restart
but in the background with the mysql_safe command like this:
 
#/usr/bin/mysqld_safe --skip-grant-tables &
 
You will se the following line
 
[1] 6831 
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6961]: started
 
You must enter the following commands exactly as shown. 
words in upper case, and having a semi-colon ( ; ) 
 
#mysql --user=root mysql 
 
It will ask you for a password. Just press the [Enter] key. 
 
At the mysql> prompt enter the following: 
update user set Password=PASSWORD('new-password-here') WHERE User='root'; 
 
NOTE: in the above command, you must use single quotes around the 
new-password-here part. MySQL will return the following:
 
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0
 
Next type the following: flush privileges; 
And then: exit
 
Now that the root password has been changed, 
 
Now just start the MySQL server with the following command:
 
#/etc/init.d/mysql start
 
You now should be able to login to your MySQL server with your new 
root password by using the following command:
 
mysql --user=root --pass=new-password
 
This should let you in to your MySQL server. 
You are here: Home / Ubuntu / Reset MySQL Root Password in Ubuntu