[英]Database connection error Access denied for user 'root'@'localhost' (using password: NO)
Whenver i go to locallhost/Blog/app/DB i encounter this error.当我 go 到本地主机/博客/应用程序/数据库时,我遇到此错误。 I have tried so many times to connect to the database but could not connect.我尝试了很多次连接到数据库但无法连接。 Even if i use my mysql password which is "root" this does not work.Please someone help me Here is my connection code:即使我使用“root”的 mysql 密码,这也不起作用。请有人帮助我这是我的连接代码:
host = "localhost";
$username = "root";
$password ="";
$db_name ="blog";
$conn = new mysqli($host, $username, $password, $db_name);
if($conn->connect_error){
die(' Database connection error '.$conn->connect_error);
}
As Indra said, avoid using root
.正如 Indra 所说,避免使用root
。 This account should only be used by a human, even in a development environment.此帐户只能由人类使用,即使在开发环境中也是如此。 If you need an account that has complete and total access to everything, create one:如果您需要一个可以完全访问所有内容的帐户,请创建一个:
CREATE USER 'indra'@'localhost' IDENTIFIED WITH mysql_native_password BY 'superSecretPassword!123';
GRANT ALL ON *.* TO 'indra'@'localhost' WITH GRANT OPTION;
The root
account in MySQL should only be used when you are configuring replication or fixing something what went really, really wrong MySQL 中的root
帐户仅应在您配置复制或修复真正错误的问题时使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.