where I can talk.

Reset MySQL/MariaDB root password on Debian 9

· Read in about 1 min · (193 Words)
MySQL

Stop the server

sudo systemctl stop mysql
# or
sudo systemctl stop mariadb

Restart the database server without permission checks

for MariaDB

sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking"
sudo systemctl start mariadb
sudo mysql -u root

for MySQL

sudo systemctl edit mysql
[Service]
ExecStart=
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid --skip-grant-tables --skip-networking

第一个 ExecStart 会清除默认值。

然后,

sudo systemctl daemon-reload
sudo systemctl start mysql
sudo mysql -u root

Change the root password

Change MariaDB password

UPDATE mysql.user SET password=PASSWORD('your_new_password') WHERE user='root';

MariaDB allows using custom authentication mechanisms, so execute the following two statements to make sure MariaDB will use its default authentication mechanism for the new password you assigned to the root account:

UPDATE mysql.user SET authentication_string='' WHERE user='root';
UPDATE mysql.user SET plugin='' WHERE user='root';

Change MySQL password

UPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE user='root';

MySQL allows using custom authentication mechanisms, so execute the following statement to tell MySQL touse its default authentication mechanism to authenticate the root user using the new password:

UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root';

Reverting your database server to normal settings

MariaDB

sudo systemctl unset-enviroment MYSQL_OPTS
sudo systemctl restart mariadb

MySQL

sudo systemctl revert mysql
sudo systemctl daemon-reload
sudo systemctl restart mysql

Refer

https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password-on-ubuntu-18-04

Comments