简体   繁体   中英

Database connection error Access denied for user 'root'@'localhost' (using password: NO)

Whenver i go to locallhost/Blog/app/DB i encounter this error. 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:

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);
}

This is my phpmyadmin user account: 在此处输入图像描述

As Indra said, avoid using 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM