无法重置MySQL(MariaDB)根密码

摩根·图维瑞·奎林(Morgan Touverey Quilling)

今天,我想在PMA中创建一个数据库。它说:“无法登录到MySQL服务器”。我通过终端尝试了同样的问题,这是因为我的密码错误。我不明白为什么。

我尝试了通常的方法来重置根密码(跳过安装授权表并重置密码),但似乎不起作用。

看到:

morgan@rakija:~$ sudo mysqld_safe --skip-grant-tables &
[1] 14016
morgan@rakija:~$ 150802 19:07:25 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
150802 19:07:25 mysqld_safe Logging to '/var/log/mysql/error.log'.
150802 19:07:25 mysqld_safe A mysqld process already exists

[1]+  Terminé 1               sudo mysqld_safe --skip-grant-tables
morgan@rakija:~$ mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.0.20-MariaDB-0ubuntu0.15.04.1 (Ubuntu)

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

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

MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> update user set password=PASSWORD("newPass") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

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

MariaDB [mysql]> exit
Bye
morgan@rakija:~$ sudo service mysql restart
morgan@rakija:~$ mysql -uroot -pnewPass
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
摩根·图维瑞·奎林(Morgan Touverey Quilling)

我发现了一个与问题本身一样奇怪的解决方案。

使用--skip-grant-tables(在Web上搜索教程)重新启动MySQL / MariaDB (完全没有必要,请在文章末尾阅读我的编辑内容)

查看中的plugin字段mysql.user

MariaDB [mysql]> SELECT user, plugin FROM user;
+------+-------------+
| user | plugin      |
+------+-------------+
| root | unix_socket |
| root | unix_socket |
| root | unix_socket |
| root | unix_socket |
+------+-------------+

我必须将每个条目的插件字段重置为空白字符串。

UPDATE user SET plugin="";   // without WHERE clause

另外,请确保已定义密码,因为有时密码似乎已被删除(在user, password字段中选择)。如果不是,请使用以下命令进行更新:

UPDATE user SET password=PASSWORD("my_password") WHERE user="root";

特权参数需要显式保存:

FLUSH PRIVILEGES;

然后,以正常模式重启MySQL,您应该能够连接到root帐户。

这不一定会禁用通过Unix套接字的连接。修复MySQL VA之后,在PMA中,我可以看到该连接是通过Unix套接字建立的。

编辑,几个月后:我现在经常遇到这个问题,我认为在MariaDB的每次更新中(或类似的东西)。因此我对探针有了更好的理解; 有一个UNIX_SOCKET插件,可以让您登录MariaDB帐户而无需创建密码,因为它使用外壳程序的凭据信任您,而无需输入任何密码。实际上,此插件是身份验证插件,而不是与SQL Server通信的方法。因此,如果您不使用unix套接字作为登录方法,则可以安全地禁用它。我唯一无法解释的是为什么在数据库的每个帐户上都定期设置UNIX_SOCKET插件,而无需我采取任何措施。

这样做的好处是,发生这种情况时,您无需重新启动MariaDB,--skip-grant-tables可以登录SQL Server :只需登录到系统的根帐户,然后直接连接而mysql -u root无需输入密码,然后在上面说明的方式。

编辑2:确认,它发生在Ubuntu上的每个MariaDB升级上。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章