无法重置 MariaDB root 密码

无法重置 MariaDB root 密码

我在做:

$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf

然后添加

跳过授权表

然后

$ sudo service mysqld restart

然后

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.1.47-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user SET PASSWORD=PASSWORD('sa') WHERE USER='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit
Bye

然后

$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf

然后删除

skip-grant-tables

然后

$ sudo service mysqld restart

然后

$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

为什么?

如果我想

MariaDB [mysql]> SET PASSWORD FOR root = PASSWORD('sa');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement

答案1

无法通过更新 mysql.user 表来管理 MySQL 凭据。

要更改用户密码,请运行以下脚本:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

相关内容