gpt4 book ai didi

php - 执行代码时,用户 'root' @'localhost' MySQL 访问被拒绝 (Windows 7)

转载 作者:行者123 更新时间:2023-11-29 22:08:29 26 4
gpt4 key购买 nike

我知道这个问题已经被问了无数次,但我已经尝试了所有提出的解决方案,但到目前为止没有一个可以解决我的问题......

所以我可以访问 phpmyadmin,我尝试过使用和不使用密码,并且它在本地主机上工作。

现在我的代码在线,但我的数据库位于本地主机上(使用 wamp)。我以前尝试过,效果很好。

当我尝试执行代码(它应该向数据库发送反馈)时,我收到此错误:

SQLSTATE[28000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:YES)

这是我连接到数据库的方式:

try {
$bdd = new PDO('mysql:host=localhost;dbname=lexcelera', 'root', 'password');
}

catch(Exception $e) {
die('Erreur : ' .$e->getMessage());
}

这是我的 config.inc:

/* Authentication type */
$cfg['Servers'][$i]['verbose'] = '';
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

有办法解决我的问题吗?另外,我使用的是 Windows 7(不幸的是,很多可能的解决方案都适用于 Linux)。

谢谢!

最佳答案

我猜你复制粘贴的配置是来自 phpmyadmin 的。确保您首先可以连接到 mysql 服务器,也许可以从命令行连接

mysql -u root -p

然后系统会要求您输入密码,请输入

password

然后按 Enter 键。

如果连接成功,则意味着您可以使用 root 帐户访问 mysql 服务器,而问题出在其他地方。

您应该检查您尝试连接的数据库 (lexcelera) 是否已创建。

如果它不起作用,则意味着您无法访问 mysql 服务器,并且意味着 mysql root 用户可能未按照粘贴文本(phpmyadmin 配置)进行配置。

关于php - 执行代码时,用户 'root' @'localhost' MySQL 访问被拒绝 (Windows 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com