简体   繁体   中英

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

my localhost is saying error like Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\\xampp\\htdocs\\registration\\includes\\db.php on line 3 on the browser I have all things done here's the image of the error in browser.

1 : here is the image which is facing the error

and also if I am doing something wrong in my code editor then here's the image of the db.php db.php files code

You may have an invalid password.

Edit: To me it looks like you're failing to actually pass parameters to the connection function, are you including / importing the variables?

This issue is tricky. But, how i went around it was straightforward. in your mysqli_connect(_,_,_,_) arrange them in this order of "localhost" , "user" , "password" , "database_name" ;

This is how you should connect your database using mysqli :

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$db = new mysqli($servername, $username, $password, $dbname);
?>

You have passed invalid credentials (user name and/or password) when trying to connect to the database. What to pass can't be answered here because only you (the database administrator) would know about the existing user accounts.

To add an user account to a MySQL database see MySQL :: MySQL 5.7 Reference Manual :: 6.3.2 Adding User Accounts[^]. This requires connecting as root and providing the root password if one has been set.

The second is a result of the first and of using the wrong error function. For mysqli_connect(), you have to call PHP: mysqli::$connect_error - Manual[^] instead of mysqli_error() upon errors: Hide Copy Code $connection = mysqli_connect ($host, $user, $password) or die('Not connected : Ah sh*t ' . mysqli_connect_error());

change back your password to null

go to mysqladmin root (C:\\xampp\\mysql\\bin) and type mysqladmin --user=root --password=oldpassword password""

dont type any character when request new password, just push enter and enter

viola refresh your phpmyadmin page,

the problem caused by changing password via command window, just change the password via phpmyadmin page to avoid such error, http://localhost/phpmyadmin

I have had the same problem trying to install OpenCart on xampp (32bit). I was completing the information that I thought was being requested when in fact all I was being asked for was the name of the database. Leave all fields as oriinal just the name of your DB. Leave password blank.

make sure this mapping is done

IN path\\xampp\\phpMyAdmin\\congig,inc

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = YOUR_DEFAULT_PASSWORD; 

and you connection file

 <?php

$servername = "localhost";
$username = "root";
$password = YOUR_DEFAULT_PASSWORD;
$db = "ecommerece";


$con = mysqli_connect($servername, $username, $password,$db);

your DB_HOST is your mysql server ip (most time is localhost)

your DB_USER is your User of Mysql (most time is root)

your DB_PASS is your Password of Mysql User (most time is none)

your DB_NAME is your name of your database in Mysql server

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