Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

php - 如何修复“警告:mysqli :: __ construct():(HY000 / 1045):用户'user'@'localhost'的访问被拒绝(使用密码:是)”(How to fix “Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES)” on MacOS)

When I try and connect to my database on XAMPP it gives me this error:

(当我尝试连接到XAMPP上的数据库时,出现此错误:)

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES)

(警告:mysqli :: __ construct():(HY000 / 1045):用户'user'@'localhost'的访问被拒绝(使用密码:是))

I have created another user and am logged in to xampp with that.

(我创建了另一个用户,并使用该用户登录到xampp。)

I use the Atom editor and am on macOS Mojave.

(我使用Atom编辑器,并且在macOS Mojave上运行。)

This is my code -

(这是我的代码-)

<?php
 $dbhost = "localhost";
 $dbuser = "username";
 $dbpass = "password";
 $db = "dbname";


$conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s
".mysqli_connect_error());
echo "Connected Successfully";
return $conn;

mysqli_connect_error();

?>

I have written username and password for confidentiality.

(为了保密起见,我已经写了用户名和密码。)

It is replaced by my real username and password in my code.

(它由我的代码中的真实用户名和密码替换。)

The same applies to the 'user'@localhost in the error message

(错误消息中的'user'@ localhost同样适用)

  ask by LeoMessi 10 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

转到您的phpadmin页面,并检查UserAccounts标签中存在的用户名和密码


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...