在XAMPP中使用phpMyAdmin时,“Connection for controluser as defined in your configuration failed”连接失败。

138

我刚刚在我的Windows XP机器上安装了XAMPP,但我收到一个错误消息:

连接到在配置文件中定义的controluser失败。

在安装XAMPP之前,我已经安装了MySQL数据库并设置了密码。我将密码更改并在MySQL的config.inc.php中进行了设置,然后出现了这个错误:

<?php
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
    $uri = 'https://';
} else {
    $uri = 'http://';
}
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/xampp/');
exit;
?>

当我尝试访问index.php时,XAMPP安装似乎出了点问题。我该怎么做才能解决这个问题?


22
在我看来,这类问题相当普遍,而且浪费大量时间来解决它们。此外,“定义范围内的问题”是否可以归为“程序员常用的软件工具”或“软件开发中独特而实际可答复的问题”也是有争议的。因此,在标记“离题”之前,请请求SO老手仔细考虑此类帖子。SO已成为一个值得信赖的一站式目的地,可以获取由曾经面对并解决过该问题的人提供的编程问题的答案。因此,对于程序员来说,在这里获得确切的答案比在其他地方搜索此类问题更有帮助。 - Dexter
我从这里找到了一个解决方案。 https://dev59.com/zVYN5IYBdhLWcg3w4br1#54176422 - manojm
15个回答

253
  1. Open phpMyAdmin in a browser and log in as root.
  2. Create a database called phpmyadmin
  3. Create a user called pma and set the "host" to the hostname or IP address of your web server (if the web server and MySQL are on the same box use localhost), make a note of the password, and grant the new user full control over the phpmyadmin database. It is recommended that this user does not have access to anything other than this database.
  4. Go to the phpMyAdmin installation directory, where you should find a sub-directory called sql.
  5. In sql you will find a file called create_tables.sql. Open it in a text editor.
  6. In phpMyAdmin, select the phpmyadmin database and click on the "SQL" tab.
  7. Copy/paste the entire text from create_tables.sql into the text box, and run the query.
  8. Open the config.inc.php file in the phpMyAdmin install directory, and add the following lines (or change the existing settings if they are already there):

    $cfg['Servers'][1]['pmadb'] = 'phpmyadmin';
    $cfg['Servers'][1]['controluser'] = 'pma';
    $cfg['Servers'][1]['controlpass'] = '<your password>';
    
    // Note: The list below may grow as PMA evolves and more control tables are added
    // Use your common sense! Don't just blindly copypasta, look at what it means!
    $cfg['Servers'][1]['bookmarktable'] = 'pma_bookmark';
    $cfg['Servers'][1]['relation'] = 'pma_relation';
    $cfg['Servers'][1]['userconfig'] = 'pma_userconfig';
    $cfg['Servers'][1]['table_info'] = 'pma_table_info';
    $cfg['Servers'][1]['column_info'] = 'pma_column_info';
    $cfg['Servers'][1]['history'] = 'pma_history';
    $cfg['Servers'][1]['recent'] = 'pma_recent';
    $cfg['Servers'][1]['table_uiprefs'] = 'pma_table_uiprefs';
    $cfg['Servers'][1]['tracking'] = 'pma_tracking';
    $cfg['Servers'][1]['table_coords'] = 'pma_table_coords';
    $cfg['Servers'][1]['pdf_pages'] = 'pma_pdf_pages';
    $cfg['Servers'][1]['designer_coords'] = 'pma_designer_coords';
    
  9. Save and close the file.

重要提示 - PMA在登录时加载配置文件,对其进行评估并将其存储到会话数据中,因此该消息将一直显示直到您执行以下操作:

  1. 退出phpMyAdmin然后重新登录

问题解决。


3
对于“退出并重新登录”的建议点赞(+1)。我浪费了五分钟才意识到这一点。 - Matthew G
14
由于某种原因,我的phpmyadmin版本将表名设为“pma__bookmark”等,有两个“下划线”。如果其他人也遇到了相同的问题,则应相应地编辑“config.inc.php”文件。顺便说一句,配置文件位于Ubuntu中的“/etc/phpmyadmin”目录中。 - ajaybc
6
在Ubuntu 14.04上,create_tables.sql的位置位于/usr/share/doc/phpmyadmin/examples/create_tables.sql.gz内。 - karlingen
2
我没有找到config.inc.php文件。 - GvSharma
5
这是一个非常好的回答(我给了你第100个"+");)。然而,我在第4步中指向的 examples 目录没有找到。相反,它在这里:/usr/share/doc/phpmyadmin/examples,我在那里找到了压缩的 SQL 文件:create_tables.sql.gz - Majid Fouladpour
显示剩余12条评论

137

如果您使用的是Debian/Ubuntu(或任何其他基于dpkg的发行版),请执行以下命令:

sudo dpkg-reconfigure phpmyadmin

phpmyadmin软件包包含用于执行此操作的脚本,它只需要一个具有权限的用户。当然,如果您已经以root用户身份登录,则不需要sudo。

编辑:尝试删除当前的phpmyadmin用户可能是值得的。


2
这对我有用,我只需要重新安装它要求的数据库。谢谢。(Ubuntu 12.04) - ino
18
在配置过程中,我不得不将控制用户的“phpmyadmin”改为“pma”才能使其正常工作。 - Hardell
2
先删除“phpmyadmin”用户,然后运行“sudo dpkg-reconfigure phpmyadmin”,这对我有用。谢谢! - B. Shea
1
注意:如果有任何配置的服务器,这将会清除它们。 - Raptor
1
@DotKu,或者配置文件位于 /etc/phpmyadmin/config-db.php,其中存储了用户名和密码。在该文件中,我必须更新为:$dbuser='pma'; 和 $dbpass='<我的密码>'; 在注销/登录后,最终摆脱了“Connection for controluser as defined in your configuration failed.”错误消息。...哦,是的,在那之前,我还必须粘贴 SQL 以创建表格。(这是另一个挣扎,因为有多个版本可用)。.............太糟糕了,这个问题已关闭,否则我会输入另一个更完整的答案。 - Elliptical view
显示剩余9条评论

25

只需在config.inc.php文件中将"User for advanced features"和"Advanced phpMyAdmin features"两个代码块全部注释掉即可。


这个有任何解释吗?这是如何以及为什么能够运作的? - Huey
1
@Ben:有时候那就是最重要的 ;) - streak
在哪些文件中...这太不具体了!但是每个人都能理解,所以我感到很愚蠢,无法修复它,哈哈双输! - Jamie Hutber
2
那将是config.inc.php。 - Rocoty
1
phpmyadmin/config.inc.php 文件中不存在类似于“高级功能用户”和“高级 phpMyAdmin 功能”的内容。 - SAYE

16

您最近更改了MySQL服务器的root密码吗?如果是,那么这就是phpMyAdmin控制台内出现错误/警告的原因。要解决此问题,只需编辑您的phpMyAdmin的config-db.php文件并设置正确的数据库密码即可。

在我看来,第一个答案过于混乱,第二个答案对我也没用。因此,在基于Linux的服务器上,该文件通常位于:

/etc/phpmyadmin/config-db.php
或:
/etc/phpMyAdmin/config-db.php

示例:(我的文件看起来像这样,并将用户从phpmyadmin更改为admin,该用户名是我通过phpmyadmin维护数据库时创建的,并输入适当的密码。)

$dbuser='phpmyadmin';
$dbpass=''; // set current password between quotes ' '
$basepath='';
$dbname='phpmyadmin';
$dbserver='';
$dbport='';
$dbtype='mysql';

致谢:http://tehnoblog.org/phpmyadmin-error-connection-for-controluser-as-defined-in-your-configuration-failed/


5

我在Ubuntu 16.04下使用phpmyadmin实现了以下方法:

我编辑了/etc/phpmyadmin/config.inc.php文件并更改了以下2行:

$cfg['Servers'][$i]['controluser'] = 'root'; 
$cfg['Servers'][$i]['controlpass'] = 'thepasswordgiventoroot'; 

3
这对我在Ubuntu 16.04下使用phpmyadmin有用:
我编辑了/etc/phpmyadmin/config.inc.php并更改了以下两行:
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = 'pass pma'; 

你救了我的一天。谢谢! - Prem Sagar
你必须解释什么是pma和传递pma。 - Xsmael

3
在Ubuntu上。
Ben的信息接近了,但问题不在于根密码,而是我在安装phpmyadmin时为其数据库创建了一个密码。 这个密码不会在ubuntu的安装中被带入,因此数据库设置文件中的变量$dbpass=''为空,并不是你设置的密码。
1. 使用以下命令登录到mysql并检查您是否拥有正确的密码:mysql -u phpmyadmin -p。尝试使用空密码,如果出现访问被拒绝的情况,请再次输入该命令,并使用您在安装过程中设置的密码。如果成功登录,则可以知道密码是什么。
2. 编辑/etc/phpadmin/config-db.php并将$dbpass=''更改为$dbpass='您的密码',然后保存文件。
3. 编辑/etc/dbconfig-common/phpmyadmin.conf并将dbc_dbpass=''更改为dbc_dbpass='您的密码',然后保存文件。关闭浏览器并重新加载页面,您会发现该消息已经消失了。

2
在 Ubuntu 操作系统中,/etc/phpmyadmin/config-db.php 是需要注意的地方。请确保这里的密码与 config.inc.php 中控制用户的密码匹配。同时,为了解决 Blowfish 密钥长度过短的问题,请编辑/var/lib/phpmyadmin/blowfish_secret.inc.php 并将密钥长度加长。请保留 HTML 标签。

2
"为了让它再次工作,我只需删除文件 ib_logfile0 和 ib_logfile1。在 MAMP 中的路径是 /Applications/MAMP/db/mysql56/ib_logfile0,在 XAMPP 中的路径是 Xampp/xamppfiles/var/mysql。这个解决方法来源于 PHP Warning: mysqli_connect(): (HY000/2002): Connection refused。请注意保留 HTML 标签。"

1

在Ubuntu上,这些步骤对我有效...

1. sudo gedit /etc/phpmyadmin/config.inc.php.

2. uncomment[remove(/)]  following lines :-

    $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

3. comment[add(/)] following lines :-     

   //$cfg['Servers'][$i]['controluser'] = $dbuser;
   //$cfg['Servers'][$i]['controlpass'] = $dbpass;

对我来说,通过执行以下操作来工作: // $cfg['Servers'][$i]['controluser'] = 'pma'; // $cfg['Servers'][$i]['controlpass'] = ''; - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接