猿问

错误 #1251 - 无法登录 MySQL 服务器

我今天买了一个 VPS 作为我的新 MySQL 服务器。我安装了 MySQL、Apache、PHP 和 phpMyAdmin。我将我的 MySQL 用户设置为“admin”。我可以在命令行上登录用户,但不能在 phpMyAdmin 中登录。我收到错误#1251 Cannot log in to the MySQL server。


问题出在运行 CentOS 6、MySQL 8.0.16 和 Apache 2.2.15 的新 Linux VPS 上。在过去 6 个小时的谷歌搜索中,我已经尝试了我遇到的一切。我将创建一个我尝试过的所有内容的列表,因为这样会更容易阅读。


- setting bind-address to 127.0.0.1

- putting my username and password into config.inc.php

- setting the host to 127.0.0.1 in config.inc.php

- trying sockets over TCP (and setting the host to localhost when using sockets)

- creating a soft-link shortcut from `/usr/share/phpmyadmin` to `/var/www/html/phpmyadmin`

- reinstalling and running mysql_secure_installation

还有很多我一时想不起来的事情。


配置文件


$cfg['Servers'][$i]['host']          = '127.0.0.1'; // MySQL hostname or IP address

$cfg['Servers'][$i]['port']          = '';          // MySQL port - leave blank for default port

$cfg['Servers'][$i]['socket']        = '';          // Path to the socket - leave blank for default socket

$cfg['Servers'][$i]['connect_type']  = 'tcp';       // How to connect to MySQL server ('tcp' or 'socket')

$cfg['Servers'][$i]['extension']     = 'mysqli';    // The php MySQL extension to use ('mysql' or 'mysqli')

$cfg['Servers'][$i]['compress']      = FALSE;       // Use compressed protocol for the MySQL connection

                                                    // (requires PHP >= 4.3.0)

$cfg['Servers'][$i]['controluser']   = '';          // MySQL control user settings

                                                    // (this user must have read-only


我的.cnf


bind-address=127.0.0.1

在尝试了所有这些之后,我没有运气,我仍然遇到同样的错误#1251 Cannot log in to the MySQL server。在这一点上,任何帮助将不胜感激,因为我越来越绝望。


编辑:问题是我用户的密码被保存为 caching_sha2_password 而不是 mysql_native_password。请参阅下面的答案。


翻翻过去那场雪
浏览 230回答 1
1回答

一只斗牛犬

首先,尝试使用以下命令禁用 SELinuxsetenforce 0通过 MySQL 提示使用查询来检查用户、主机和密码插件。SELECT user, host, plugin from mysql.user插件必须设置为“mysql_native_password,主机应该是本地主机。如果不是,你可以通过以下方式更新你的插件: UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'admin'并更新主机:UPDATE mysql.user SET host = 'localhost' WHERE User = 'admin'
随时随地看视频慕课网APP
我要回答