phpMyAdmin 连接 MySQL 服务器失败

Posted

技术标签:

【中文标题】phpMyAdmin 连接 MySQL 服务器失败【英文标题】:phpMyAdmin Failed to Connect to the MySQL Server 【发布时间】:2021-09-20 01:11:14 【问题描述】:

我使用 XAMPP 运行 phpMyAdmin,但它一直显示以下错误:

phpMyAdmin 尝试连接 mysql 服务器,但服务器拒绝连接。您应该检查配置中的主机、用户名和密码,并确保它们与 MySQL 服务器管理员提供的信息相对应。

看起来像这样:

这是我的 config.inc 脚本:

/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 */
$cfg['blowfish_secret'] = 'xampp'; /* YOU SHOULD CHANGE THIS FOR A MORE SECURE COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0;

/*
 * First server
 */
$i++;

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Lang'] = '';

/* Bind to the localhost ipv4 address and tcp */
$cfg['Servers'][$i]['host'] = 'localhost:3307';
$cfg['Servers'][$i]['connect_type'] = 'tcp';

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = '';

/* Advanced phpMyAdmin features */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';

/*
 * End of servers configuration
 */

?> ```


【问题讨论】:

【参考方案1】:

(A) 对于您的情况,您使用 config 作为身份验证类型:

$cfg['Servers'][$i]['auth_type'] = 'config';

首先,请为phpmyadmin创建一个用户:

sudo mysql --user=root mysql -p

然后

CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;

FLUSH PRIVILEGES;

然后,编辑 config.inc.php 文件。您可以在“C:\xampp\phpmyadmin”中找到它并更改:

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = ''; 

$cfg['Servers'][$i]['user'] = 'phpmyadmin';
$cfg['Servers'][$i]['password']  = 'some_pass';

(B) 另一种方法(我认为更安全)是使用以下方法:

$cfg['Servers'][$i]['auth_type'] = 'http';

在这种情况下,phpmyadmin 会弹出一个框,要求您输入用户名和密码。

【讨论】:

如果我使用第一个解决方案,它会给我这个错误: mysqli::real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using密码:是) 我修改了答案,请尝试(a)和(b)两种方法看看效果。谢谢

以上是关于phpMyAdmin 连接 MySQL 服务器失败的主要内容,如果未能解决你的问题,请参考以下文章

如何解决 phpmyadmin 在 localhost 中无法访问?

#2002 -lampp phpmyadmin

Mac下php连接mysql数据库失败解决办法

从 php 文件到 phpmyadmin 的数据库连接失败?

配置中定义的 controluser 连接失败。 #1045 无法登录 MySQL 服务器

phpmyadmin登录后显示“使用配置文件中定义的控制用户连接失败。”错误提示