请问Access denied for user 'username'@'hostname' (using password_ YES)
错误消息:
Access denied for user 'username'@'hostname' (using password: YES)
#1044 - Access denied for user 'username'@'hostname' to database 'database_name'
原因:
- 用户没有足够的权限访问数据库或表。
- 用户密码错误或未授权。
解决方法:
-
检查用户名和密码:
- 确认用户名和密码是否正确。
- 确认用户是否具有相应的权限。
$username = "your_username"; $password = "your_password"; $dbname = "ecms"; // 创建连接 $conn = new mysqli("localhost", $username, $password, $dbname); // 检查连接 if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
-
授予数据库权限:
- 登录到 MySQL 服务器并授予相应的权限。
GRANT ALL PRIVILEGES ON ecms.* TO 'your_username'@'localhost' IDENTIFIED BY 'your_password'; FLUSH PRIVILEGES;
-
检查数据库用户:
- 确认用户是否存在并具有相应权限。
SELECT User, Host FROM mysql.user;
更新时间:2025-04-10 23:42:45
转载请注明原文链接:https://www.muzicopy.com/suibi/3253.html