且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连接失败:用户 ''username'@'localhost' 访问被拒绝(使用密码:YES)

更新时间:2023-12-01 20:57:52

要么用户没有数据库所需的权限,要么密码错误.

Either the user does not have the required rights for the database or the password is wrong.

否则删除用户并使用以下语句创建:

Otherwise remove the user and use the following statement to create:

1.CREATE USER 'user'@'localhost' IDENTIFIED BY '123456789';
2.
3.GRANT ALL PRIVILEGES ON project.* TO 'user'@'localhost' WITH GRANT OPTION;

或者试试这个:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
//Create
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli($servername, $username, $password, $dbname);

echo "Yaaay";