MySQL报错:无法连接,设置无效。xampp。

83
我将root密码更改为“test”,现在无法登录XAMPP中的phpMyAdmin页面。 我在这里这里寻求帮助,基本上说要更改 XAMPP \ PHPMYADMIN 文件夹中的 config.inc.php 文件。
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'test';    <---- changed this
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'test'; <--- I changed this too (Edit: Not needed)

下面的代码有效,使用上述密码

if($_SERVER['REMOTE_ADDR']=="127.0.0.1")
{
define("DATABASE_SERVER", "localhost");
define("DATABASE_USERNAME", "root");
define("DATABASE_PASSWORD", "test");
define("DATABASE_NAME", "TIGERWOODS");
} 

这种情况曾经在我的Mac上发生过,但我无法解决。现在在WinXP上又出现了。我正在使用Xampp 1.7.4。

21个回答

69

我也遇到了同样的问题,所以我去了:

/xampp/phpmyadmin/config.inc.php

我复制了之前输入的密码,然后我又能够访问phpmyadmin了,在“特权”选项卡/编辑中选择不需要密码,然后就都恢复正常了 :)

另外,你可以将用户更改为管理员,但你的phpmyadmin将在管理员侧,其他本地主机网站也无法工作。


1
最简单和最整洁的解决方案。 - Charmie

56

我也遇到了同样的问题,花了几个小时才弄清楚。

我只是把 'config' 改成了 'cookie'

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

这对我也有效!能否请您提供更多的解释? - Abdalla Abdalmunim
这是什么鬼,我已经尝试了各种方法,但只有这个可行。 - Bariq Dharmawan
2
为什么这个有效? - Robin Bastiaan
终于找到了解决这个问题的方法,太棒了! - PHPFan
去这个路径了解答案:/opt/lampp/phpmyadmin 并且编辑config.inc.php。 - Adewale Muritala Akinyemi
这个答案太棒了 - Ramjay Romorosa

43
$cfg['Servers'][$i]['host'] = '127.0.0.1:3307'; 

如果您更改端口地址


1
这解决了我的问题,为了更加明确:默认端口是3306,所以如果你在my.ini中将该数字更改为另一个数字,则还需要在config.inc.php中进行更改。 - Wael Alshabani
以上更改需要在xampp-> Apache-Config->phpmyadmin(config.inc.php)中进行, 或者 您可以直接访问以下地址: C:\xampp\phpMyAdmin\config.inc.php - Shamsul Haque

23

上述代码解决了大多数人的问题,但我仍然无法登录。最后我发现需要更改以上代码中的第9行。

$cfg['Servers'][$i]['AllowNoPassword'] = true;   <--- change this
$cfg['Servers'][$i]['AllowNoPassword'] = false;  <--- to this fixed the problem.

注意:在本地主机中,还有其他需要手动更改密码的区域。例如,在“CD收藏”示例中。该密码是硬编码的,而不是从config.inc.php中获取。


22

我也遇到了同样的问题,原因是另一个mysql服务正在运行,并且我同时尝试运行xampp中的mysql。如果其他解决方案不起作用,您可以通过以下命令停止它:

sudo service mysql stop
sudo service mysql stop

可能会帮助一些用户。


15

你只需要通过任务管理器停止 mysqld.exe,然后重新启动服务器(Xammp)。


运行得很好。不知道为什么。 - ajinzrathod

15

9
**Step1**: Go to xampp/phpMyAdmin/config.inc.php
**Step2**: Search this: $cfg['Servers'][$i]['host'] = '127.0.0.1';
**Step3**: Replace with $cfg['Servers'][$i]['host'] = '127.0.0.1:3307';

Here 3307 will be change  with your mysql port number, in my case it is 3307. Most of the times it will be 3306.

You can check your mysql port number from here : xampp/mysql/bin/my.ini

5

我也遇到了这个问题,但现在已经解决了

$cfg['Servers'][$i]['user'] = 'admin'; - 我将用户名从'root'改为'admin'


2

可能有另一个mysqld实例正在运行,您可以使用以下命令停止它:

sudo service mysql stop

对我很有效。


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