Business Internet and Telephony, since 1985

Recover and reset MySQL and MariaDB root password

Printer-friendly versionPrinter-friendly versionSend by emailSend by email

We're always getting asked this stuff, So here it is as a tutorial in concise, cookbook format:

If you're not running Slackware, then the command to start and stop the mysql daemon might be something like /etc/init.d/mysql start|strop|restart, FYI - YMMV.

 

# /etc/rc.d/rc.mysqld stop
# mysqld_safe --skip-grant-tables &
# mysql -uroot
mysql> use mysql;
mysql> update user set password=PASSWORD("your-new-pwd") where User='root';
mysql> flush privileges;
mysql> exit
# /etc/rc.d/rc.mysqld stop
# /etc/rc.d/rc.mysqld start
# mysql -uroot -p

and enter your-new-pwd

 

If you just need to reset a known MySQL or MariaDB root password then you can do the following using the mysqladmin utility:

 

$ mysqladmin -uroot -p'old-root-pwd' password '-newr-root-pwd'

 

This method works for regular MySQL users too who wish to change their passwords:

 

$ mysqladmin -ujoeuser -p old-pwd-for-joeuser password new--pwd-for-joeuser

 

To change a password from within the running mysql client, do the following:

 

$ mysql -uroot -p
mysql> use mysql;
mysql> update user set password=PASSWORD("new-pwd-for-joeuser") where User='joeuser';
mysql> flush privileges;
mysql> exit

 

Enjoy!