1. 程式人生 > >How to Reset the root's Password for MySQL(MariaDB)

How to Reset the root's Password for MySQL(MariaDB)

Unfortunately, I had forgotten the root's password of MySQL.

Here, one of the methods is introduced, which works on my RasberryPi 3B+.

  1. Kill the process MySQL
    sudo killall mysqld
    
    #or
    
    sudo /etc/init.d/mysql stop
  2. Start the mysqld with grant tables being skipped
    MySQLd --skip-grant-tables &
  3. Login the mysql without password
    mysql -u root
  4. Update the password and flush the privileges
    MySQL> update MySQL.user set password=PASSWORD('newpassword') where User='root';  
    MySQL> flush privileges;  
    MySQL> quit
  5. Restart the mysql
    sudo /etc/init.d/mysql restart