phpMyAdmin 無法登入 Centos 7 上的 MySQL 伺服器



我用Nginx在Centos 7上安装了mysql-community-server-8.0.13-1.el7.x86_64,并添加了phpMyAdmin来管理数据库,但我不断收到phpMyAdmin的错误Cannot log in to the MySQL server。我已经尝试了以下方法,并且已经挣扎了几天:

  • 更改了位于/etc/phpMyAdmin/config.inc.php上的一些参数(在堆栈溢出上建议),如下所示,但没有运气:

    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['connect_type'] = 'socket';
    $cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';
    $cfg['Servers'][$i]['user'] = 'root';          
    $cfg['Servers'][$i]['password'] = 'password'; 
    
  • 我已经尝试过mysql shell,并且能够与root和其他用户一起登录。但是,我不知道为什么它在phpMyAdmin上失败。请帮助和感谢!

我能够通过执行以下操作来解决此问题:(我应该提到这个解决方案适用于MySQL 8.0.13和phpMyAdmin 4.8.4 - 两者都是最新版本)

1-我使用这些服务器参数编辑了config.inc.php(仅):

/*** This is needed for cookie based authentication to encrypt password in 
cookie. Needs to be 32 chars long. */
$cfg['blowfish_secret'] = 'generate_your_blowfish_secret_32_chars'; 
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

2-在MySQL终端上

//Create a new user:
mysql> CREATE USER 'user'@'localhost' IDENTIFIED BY 'your_password';
//Grant all privileges:
mysql> GRANT ALL PRIVILEGES ON *.* To 'user'@'localhost' WITH GRANT OPTION;
//Flush all privileges:
mysql> FLUSH PRIVILEGES;
//Change authentication_string with password:
mysql> ALTER USER user IDENTIFIED WITH mysql_native_password BY 
'your_password';
//Login with the new user and password!

这应该允许您登录到phpMyAdmin。我希望这有帮助!

这对我来说是:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourNewPassword';

在 CentOS 7 上,我必须:

  1. 取消注释/etc/my.cnf 中的"default-authentication-plugin=mysql_native_password"行(然后系统CTL重新启动MySQLd)

  2. 更改用户"
  3. 用户"@"本地主机",通过"您的密码"标识mysql_native_password;

对上面雅克曼接受的答案进行了小幅调整。我已经尝试了其他所有方法,但缺少"WITH mysql_native_password"条款