今天,我想在 PMA 中创建一个数据库。它说:“无法登录到 MySQL 服务器”。我通过终端尝试过,同样的问题,这是因为我的密码错误。我不明白为什么。
我尝试了常用的方法来重置 root 密码(跳过授权表安装并重置密码),但似乎不起作用。
看到:
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'
Run Code Online (Sandbox Code Playgroud)
Mor*_*ing 62
我找到了一个和问题本身一样奇怪的解决方案。
使用(完全没有必要,请在帖子末尾阅读我的编辑)--skip-grant-tables(在网上搜索教程)重新启动 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 |
+------+-------------+
Run Code Online (Sandbox Code Playgroud)
我不得不将每个条目的插件字段重置为空字符串。
UPDATE user SET plugin=""; // without WHERE clause
Run Code Online (Sandbox Code Playgroud)
此外,请确保定义了密码,因为有时它似乎已被删除(在user, password字段上选择)。如果没有,请更新:
UPDATE user SET password=PASSWORD("my_password") WHERE user="root";
Run Code Online (Sandbox Code Playgroud)
需要显式保存权限参数:
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)
然后,以正常模式重新启动 MySQL,您应该能够连接到 root 帐户。
这不一定会禁用通过 Unix 套接字的连接。我的 MySQL va 修复后,在 PMA 中,我可以看到连接是通过 Unix socket 建立的。
编辑,几个月后:我现在已经习惯了这个问题经常出现,我想在每次更新 MariaDB(或类似的东西)时。所以我对probem有了更好的理解;有一个 UNIX_SOCKET 插件可以让您登录 MariaDB 帐户而无需创建密码,因为它使用 shell 的凭据来信任您,而无需输入任何密码。实际上,这个插件是一个身份验证插件,而不是一种与 SQL 服务器通信的方法。因此,如果您不使用 unix socket 作为登录方法,则可以安全地禁用它。我唯一无法解释的是为什么 UNIX_SOCKET 插件定期设置在数据库的每个帐户上,而我这边没有任何操作。
这有一个很好的副作用,当它发生时,您可以登录到 SQL 服务器而无需重新启动 MariaDB --skip-grant-tables:只需登录系统的 root 帐户,然后mysql -u root无需密码即可连接,然后重置插件字段上面解释的方式。
编辑 2:确认,它发生在 Ubuntu 上的每个 MariaDB 升级中。
小智 5
从这个答案,http://ubuntuforums.org/showthread.php?t=2275033&p=13272227#post13272227。
Mysql 尝试使用插件而不是密码对 root 进行身份验证。您需要禁用 root 的插件使用。
shell$ sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56775 次 |
| 最近记录: |