Simple method to reset MySQL or MariaDB root password in CLI

To reset your MySQL root password in SSH, simply run the following sequence of commands:


/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
update user set password=PASSWORD("newrootpassword") where User='root';
flush privileges;
quit
/etc/init.d/mysqld stop
/etc/init.d/mysqld start

On Fedora 7.x based systems, which come with MariaDB instead of MySQL, run:


systemctl stop mariadb
mysqld_safe --skip-grant-tables &
mysql -u root
use mysql;
update user set password=PASSWORD("newrootpassword") where User='root';
flush privileges;
quit
systemctl stop mariadb
systemctl start mariadb

Tags:

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.