【发布时间】:2012-02-21 01:42:32
【问题描述】:
我的 XAMPP 正在运行 apache 和 mysql 正在运行并尝试一个简单的 mysql_connect
mysql_connect('localhost', 'root', 'test123');
但是 mysql_error() 回来了
无法连接到 MySQL 主机。 用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)
所以,我在 myphpadmin 中打开了 config.inc.php 并验证了凭据是否正确。
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'test123';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
我唯一不确定的是 $cfg['Servers'][$i] 东西。这是什么$i?是否有多个服务器实例?
【问题讨论】:
-
您是尝试从自己的脚本还是从 PhpMyAdmin 连接到 MySQL?
-
也许这可以回答你的问题。 stackoverflow.com/questions/6445917/…
-
好的,我知道了。故事的寓意是不要使用root,并生成一个用户名和密码,它就起作用了。