mySQL: How to reset root password

If the password for the mysql “root” user is lost, it’s still possible reset it to some other value.
The restart of the mySQL server will be necessary, of course.

The following should be done:

Stop the server
It could be done normally:

/etc/init.d/mysql stop

or effectively:

ps -ef | grep mysql
...
mysql 25079 1 0 Jan 31 ? 0:00 /usr/bin/mysqld
...
kill -9 25079

Please ensure that the proper process is killed!

Start MySQL server without security checking

mysqld_safe --skip-grant-tables &

Connect to mySQL without password

mysql -u root

Reset mySQL root password

use mysql;
update user set password=PASSWORD("NEW_PASSWORD") where user='root';
flush privileges;

Use the real new password instead of the string “NEW_PASSWORD”.

Restart mySQL server

/etc/init.d/mysql stop
/etc/init.d/mysql start

Check the connection

mysql -u root -p

mysql: rownum functionality

Here are some examples how to use “rownum” functionality (similar to Oracle) in mysql


update mytable
set col1 = 'somevalue'
order by col2
limit 300

rownum analog:


select @rownum:=@rownum+1 rownum, mytable.*
from (select @rownum:=0) r, mytable;