繁体   English   中英

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

[英]Error #1251 - Cannot log in to the MySQL server

我今天购买了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上。 在过去六个小时的谷歌搜索中,我已经尝试了所有遇到的问题。 我将创建一个清单,其中列出了我尝试过的所有内容,因为这些内容将更易于阅读。

- 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

还有很多我现在还不记得的事情。

config.inc.php文件

$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
$cfg['Servers'][$i]['controlpass']   = '';          // access to the "mysql/user"
                                                    // and "mysql/db" tables).
                                                    // The controluser is also
                                                    // used for all relational
                                                    // features (pmadb)
$cfg['Servers'][$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user']          = 'admin';     // MySQL user
$cfg['Servers'][$i]['password']      = 'areallygoodpassword';  // MySQL password (only needed

httpd.conf文件

<IfModule php5_module>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
</IfModule>

LoadModule php5_module modules/libphp5.so
AddType x-httpd-php .php
AddHandler php5-script .php

phpMyAdmin.conf

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   Order Allow,Deny
   Allow from All
</Directory>

my.cnf中

bind-address=127.0.0.1

在尝试了所有这些之后,我没有运气,并且仍然遇到相同的错误#1251 Cannot log in to the MySQL server 由于我不顾一切,在这一点上任何帮助将不胜感激。

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

  1. 首先,尝试使用以下命令禁用SELinux
    setenforce 0

  2. 通过在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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM