Reset Forgotten MySQL Root Password

We’re using MySQL 5.5 and Debian Wheezy in this example. 

Stop MySQL service:

# /etc/init.d/mysql stop

Start MySQL in a safe mode, skip grant tables and networking:

# mysqld_safe --skip-grant-tables --skip-networking &

Log in as root:

# mysql -u root

Reset MySQL root password:

mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('changeme');
mysql> FLUSH PRIVILEGES;
mysql> exit;

Kill mysqld_safe process:

# for i in $(ps -eo pid,comm|grep mysql|awk '{print $1}');do kill -9 $i;done

Start MySQL service:

# /etc/init.d/mysql start

Leave a Reply

Your e-mail address will not be published. Required fields are marked *