我尝试在WAMP中连接到我的数据库,它首先给了我SQLSTATE[HY000] [1045] Access denied for user 'C:/wamp/www'@'localhost' (using password: NO).
我之后更改了密码但仍然获得SQLSTATE[HY000] [1045] Access denied for user 'C:/wamp/www'@'localhost' (using password: YES)
。
在phpmyadmin中,我添加了密码,但没有任何变化。这是config.inc的代码:
<?php
/* Servers configuration */
$i = 0;
$cfg['blowfish_secret'] = 'h]C+{nqW$omNoTIkCwC$%z-LTcy%p6_j$|$Wv[mwngi~|e'; //What you want
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'Local Databases';
$cfg['Servers'][$i]['host'] = 'localhost';//127.0.0.1
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'father2242';
// Hidden databases in PhpMyAdmin left panel
//$cfg['Servers'][$i]['hide_db'] = '(information_schema|mysql|performance_schema|sys)';
// Allow connection without password
$cfg['Servers'][$i]['AllowNoPassword'] = true;
// Suppress Warning about pmadb tables
$cfg['PmaNoRelation_DisableWarning'] = true;
// To have PRIMARY & INDEX in table structure export
//$cfg['Export']['sql_drop_table'] = true;
//$cfg['Export']['sql_if_not_exists'] = true;
$cfg['MySQLManualBase'] = 'http://dev.mysql.com/doc/refman/5.7/en/';
/* End of servers configuration */
?>
对于我的数据库连接参数(db.ini):
;MySQLi hostname
host = localhost
;MySQLi Username
user = root
;MySQLi Password
pass = father2242
;MySQLi Table - Database
name = ddrive
访问连接的脚本(database.php)
<?php
function DB() {
$dbconfig = (object) parse_ini_file(__DIR__.'/../ini/db.ini');
try {
$db = new PDO(
"mysql:host={$dbconfig->host};dbname={$dbconfig->name}",
$dbconfig->user,
$dbconfig->pass
);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
} catch (PDOException $e) {
die($e->getMessage());
}
}
?>
为什么我收到此错误?我愿意接受建议或批评。
答案 0 :(得分:0)
错误&#39; C:/ wamp / www&#39; @&#39; localhost&#39;告诉您尝试连接的用户是&#39; C:/ wamp / www&#39;,而不是&#39; root&#39;。你可以通过打印来检查$ dbconfig里面的内容吗?
在phpmyadmin config中更改密码并不能实际更改数据库本身的密码。 Phpmyadmin只是一个客户端,而不是数据库。
要更改数据库中的密码,您应该在&#39;用户&#39;表格&#39; mysql&#39;使用任何客户端的数据库(如phpmyadmin):
从phpmyadmin配置中删除用户名和密码 - 它允许您使用网络表单登录。
打开phpmyadmin并使用默认用户/密码对。最有可能的是&#39; root&#39;默认情况下没有密码。
转到用户表,搜索&#39; root&#39;用户使用&#39; localhost&#39;主持并将密码更改为PASSWORD(&#39; father2242&#39;)
保存行
重启MySQL服务
之后一切都应该工作 - 您将允许root用户使用您选择的密码从localhost访问。
答案 1 :(得分:0)
不确定为什么修改了config.inc.php
文件,没有必要。
如果您将这两行更改回原始状态
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'father2242';
是
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
当你运行phpMyAdmin时,你应该看到phpMyAdmin
登录页面。
注意:默认情况下,root
用户ID没有设置密码,就像大多数MySQL安装一样。
因此请使用Username = root
并离开password blank
,这会将您作为root
帐户登录。
如果您确实在root帐户上设置了密码,则可以在登录页面中使用该密码。