how to reset the mysql root password

forgot the mysql root password? here are a couple of quick fixes:

first:

  • create a file with the sql commands to change the root password.

  • stop mysql

  • launch mysql with that file as an init file argument.

cat > /root/reset.root.sql <<EOM
update mysql.user set Password = password('MYnewPASSword') where User = 'root';
flush privileges;
EOM
service mysql stop
mysqld_safe --init-file /root/reset.root.sql
service mysql start
rm /root/reset.root.sql

second:

this method is not secure, but a bit simpler. just run the server with _ no _ security at all. the pid file location used is just an example:

service mysql stop
mysqld_safe --skip-grant-tables --skip-networking
mysql <<EOM
update mysql.user set Password = password('MYnewPASSword') where User = 'root';
flush privileges;
quit;
EOM
kill `cat /var/run/mysql/mysqld.pid`
service mysql start