在 WAMP 中拒绝用户访问
Getting access denied for user in WAMP
我尝试在 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());
}
}
?>
为什么会出现此错误?我愿意接受建议或批评。
错误 'C:/wamp/www'@'localhost' 告诉您尝试连接的用户是 'C:/wamp/www',而不是 'root'。你能通过打印出来检查 $dbconfig 里面到底有什么吗?
在 phpmyadmin 配置中更改密码实际上并没有从数据库本身更改密码。 Phpmyadmin 只是一个客户端,不是数据库。
要从数据库更改密码,您应该使用任何客户端(如 phpmyadmin)在 'users' table 数据库中更改密码:
从 phpmyadmin 配置中删除用户名和密码 - 它将允许您使用网络表单登录。
打开 phpmyadmin 并使用默认的 user/password 对。默认情况下很可能是 'root' 没有密码。
转到用户 table,使用 'localhost' 主机搜索 'root' 用户并将密码更改为 PASSWORD('father2242')
保存行
重启MySQL服务
之后一切都应该正常 - 您将允许 root 用户使用您选择的密码从本地主机访问。
不知道为什么要修改config.inc.php
文件,没有必要。
如果将这两行改回原来的状态
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'father2242';
这是
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
当您 运行 phpMyAdmin 时,您应该看到 phpMyAdmin
登录页面。
注意:与大多数 MySQL 安装一样,root
用户 ID 默认没有设置密码。
因此请使用 Username = root
并保留 password blank
,这将使您以 root
帐户登录。
如果您确实为 root 帐户设置了密码,那么您可以在登录页面中使用该密码。
我尝试在 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());
}
}
?>
为什么会出现此错误?我愿意接受建议或批评。
错误 'C:/wamp/www'@'localhost' 告诉您尝试连接的用户是 'C:/wamp/www',而不是 'root'。你能通过打印出来检查 $dbconfig 里面到底有什么吗?
在 phpmyadmin 配置中更改密码实际上并没有从数据库本身更改密码。 Phpmyadmin 只是一个客户端,不是数据库。
要从数据库更改密码,您应该使用任何客户端(如 phpmyadmin)在 'users' table 数据库中更改密码:
从 phpmyadmin 配置中删除用户名和密码 - 它将允许您使用网络表单登录。
打开 phpmyadmin 并使用默认的 user/password 对。默认情况下很可能是 'root' 没有密码。
转到用户 table,使用 'localhost' 主机搜索 'root' 用户并将密码更改为 PASSWORD('father2242')
保存行
重启MySQL服务
之后一切都应该正常 - 您将允许 root 用户使用您选择的密码从本地主机访问。
不知道为什么要修改config.inc.php
文件,没有必要。
如果将这两行改回原来的状态
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'father2242';
这是
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
当您 运行 phpMyAdmin 时,您应该看到 phpMyAdmin
登录页面。
注意:与大多数 MySQL 安装一样,root
用户 ID 默认没有设置密码。
因此请使用 Username = root
并保留 password blank
,这将使您以 root
帐户登录。
如果您确实为 root 帐户设置了密码,那么您可以在登录页面中使用该密码。