简体   繁体   English

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

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

I bought a VPS today to use as my new MySQL server. 我今天购买了VPS用作新的MySQL服务器。 I installed MySQL, Apache, PHP, and phpMyAdmin. 我安装了MySQL,Apache,PHP和phpMyAdmin。 I set up my MySQL user as "admin". 我将MySQL用户设置为“ admin”。 I am able to log into the user on the command-line, but not in phpMyAdmin. 我可以在命令行上登录用户,但不能在phpMyAdmin中登录。 I get the error #1251 Cannot log in to the MySQL server . 我收到错误#1251 Cannot log in to the MySQL server

The issue is on a new Linux VPS running CentOS 6, MySQL 8.0.16, and Apache 2.2.15. 问题出在运行CentOS 6,MySQL 8.0.16和Apache 2.2.15的新Linux VPS上。 I have tried everything I came across in the past 6 hours of googling. 在过去六个小时的谷歌搜索中,我已经尝试了所有遇到的问题。 I will create a list of everything I've tried since that will be easier to read. 我将创建一个清单,其中列出了我尝试过的所有内容,因为这些内容将更易于阅读。

- 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

and a lot more things that I can't quite recall at the moment. 还有很多我现在还不记得的事情。

config.inc.php 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 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 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 my.cnf中

bind-address=127.0.0.1

After trying all of this, I have had no luck and I am still getting the same error #1251 Cannot log in to the MySQL server . 在尝试了所有这些之后,我没有运气,并且仍然遇到相同的错误#1251 Cannot log in to the MySQL server Any help would be greatly appreciated at this point, as I am getting desperate. 由于我不顾一切,在这一点上任何帮助将不胜感激。

EDIT: The issue was my user's passwords were saved as caching_sha2_password instead of mysql_native_password. 编辑:问题是我的用户密码保存为caching_sha2_password而不是mysql_native_password。 See the answer below. 请参阅下面的答案。

  1. First, try by disabling the SELinux by using the command 首先,尝试使用以下命令禁用SELinux
    setenforce 0

  2. check user, host and password plugin by using query through MySQL prompt. 通过在MySQL提示符下使用查询来检查用户,主机和密码插件。

SELECT user, host, plugin from mysql.user

plugin must be set to "mysql_native_password, and the host should be localhost. if it is not you can update your plugin by: UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'admin' 插件必须设置为“ mysql_native_password,主机应为本地主机。如果不是,则可以通过以下方式更新插件: UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'admin'

and update host: 并更新主机:

UPDATE mysql.user SET host = 'localhost' WHERE User = 'admin'

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

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