我尝试在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());
}
}
?>我为什么要犯这个错误?我愿意接受建议或批评。
发布于 2017-07-30 23:00:56
错误'C:/wamp/www'@'localhost‘告诉您试图连接的用户是'C:/wamp/www',而不是'root’。你能通过打印出来来检查一下$dbconfig里面到底是什么吗?
在phpmyadmin配置中更改密码实际上并不会更改数据库本身的密码。Phpmyadmin只是一个客户端,而不是数据库。
要从数据库中更改密码,您应该使用任何客户机(如phpmyadmin)在“mysql”数据库中的“用户”表中更改密码:
在此之后,一切都应该正常工作--您将允许根用户使用您选择的密码从本地主机访问。
发布于 2017-07-31 08:24:48
不知道为什么要修改config.inc.php文件,没有必要。
如果您将这2行更改为原始状态
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'father2242';这是
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';当您运行phpMyAdmin时,应该向您显示phpMyAdmin登录页面。
注意:默认情况下,root用户by没有设置密码,就像大多数MySQL安装一样。
因此,使用Username = root并保留password blank,这将将您作为root帐户登录。
如果您确实在根帐户上设置了密码,那么您可以在登录页面中使用该密码。
https://stackoverflow.com/questions/45405450
复制相似问题