My notepad

Chris' IT notes…
← Back

MySQL Reset admin root password

Recommended method:

  1. Create file /var/lib/mysql/mysql.init with contents:
sh
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('mynewpassword');
  1. Add this line to /etc/my.cnf in the [mysqld] section:
sh
init_file=/var/lib/mysql/mysql.init
  1. Restart the MySQL service
  2. At your leisure, delete the mysql.init file and remove the init_file line from /etc/my.cnf

With MARIADB

Source: https://stroobants.io/reset-a-root-password-in-mariadb-on-linux/

sh
service mysql stop
mysqld_safe --skip-grant-tables --skip-networking &

# mysql
use mysql;
update user set password=PASSWORD("<PASSWORD>") where User='root'
flush privileges;
exit

service mysql restart