MySQL Reset Root Passwd

From TheBestLinux.com
Jump to navigation Jump to search

Resetting Root User Password in MySQL/MariaDB Server

  • MUST be run as the root/super user from the Linux command line.
  • Stop MySQL/MariaDB Database Server:


# systemctl stop mysqld.service
    OR


# systemctl stop mariadb.service
  • Confirm the DB server has stopped:


# ps ax | grep sql
  • If there is an instance, do a killall mysqld_safe
  • Start MySQL Server skipping grant tables, allowing for no password logins:


# mysqld_safe --skip-grant-tables
  • Log into MySQL Database server as root user without password:


# mysql --user=root mysql
  • Reset MySQL root user password:


# update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;
  • Exit MySQL and test by logging back in as root user and prompting for password:
# mysql -u root -p