简体   繁体   English

(HY000/1045) 用户 'root'@'localhost' 访问被拒绝(使用密码:是)

[英](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.我的本地主机说错误,如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浏览器上第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我已完成所有操作,这是浏览器中错误的图像。

1 : here is the image which is facing the error 1这是面临错误的图像

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并且如果我在我的代码编辑器中做错了什么,那么这里是 db.php db.php 文件代码的图像

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" ;在你的mysqli_connect(_,_,_,_)中按照"localhost" , "user" , "password" , "database_name"顺序排列它们;

This is how you should connect your database using mysqli :这是你应该如何使用 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[^].要将用户帐户添加到 MySQL 数据库,请参阅 MySQL :: MySQL 5.7 参考手册 :: 6.3.2 添加用户帐户[^]。 This requires connecting as root and providing the root password if one has been set.这需要以 root 身份连接并提供 root 密码(如果已设置)。

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());对于 mysqli_connect(),你必须调用 PHP: mysqli::$connect_error - Manual[^] 而不是 mysqli_error() 在错误时:隐藏复制代码 $connection = mysqli_connect ($host, $user, $password) or die('未连接:啊 sh*t ' . mysqli_connect_error());

change back your password to null将您的密码改回 null

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

dont type any character when request new password, just push enter and enter请求新密码时不要输入任何字符,只需按 Enter 并输入

viola refresh your phpmyadmin page, viola 刷新您的 phpmyadmin 页面,

the problem caused by changing password via command window, just change the password via phpmyadmin page to avoid such error, http://localhost/phpmyadmin通过命令窗口修改密码导致的问题,通过phpmyadmin页面修改密码即可避免此类错误, http://localhost/phpmyadmin

I have had the same problem trying to install OpenCart on xampp (32bit).我在尝试在 xampp(32 位)上安装 OpenCart 时遇到了同样的问题。 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 IN路径\\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)您的 DB_HOST 是您的 mysql 服务器 ip(大部分时间是本地主机)

your DB_USER is your User of Mysql (most time is root)你的 DB_USER 是你的 Mysql 用户(大部分时间是 root)

your DB_PASS is your Password of Mysql User (most time is none)您的 DB_PASS 是您的 Mysql 用户密码(大多数情况下没有)

your DB_NAME is your name of your database in Mysql server您的 DB_NAME 是您在 Mysql 服务器中的数据库名称

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE [HY000] [1045] 用户'root'@'localhost'的访问被拒绝(使用密码:YES)symfony2 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) symfony2 SQLSTATE [HY000] [1045]拒绝用户&#39;root&#39;@&#39;localhost&#39;的访问(使用密码:是)错误 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) error occurs SQLSTATE[HY000] [1045] 用户'root'@'localhost'的访问被拒绝(使用密码:YES)? - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)? Symfony-理论:用户&#39;root&#39;@&#39;localhost&#39;的SQLSTATE [HY000] [1045]访问被拒绝(使用密码:是) - Symfony - doctrine: SQLSTATE[HY000] [1045] access denied for user 'root'@'localhost' (using password: YES) Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (使用密码: YES) - Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) PHP Owncloud [1045] SQLSTATE [HY000] [1045]用户&#39;ownclouduser&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是) - PHP Owncloud [1045] SQLSTATE[HY000] [1045] Access denied for user 'ownclouduser'@'localhost' (using password: YES) 警告:mysqli_connect():(HY000/1045):用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:YES)无法连接数据库 - Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) Could not connect database Wordpress错误:(HY000 / 1045):用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是)1538行上的wp-db.php - Wordpress error: (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) wp-db.php on line 1538 SQL: select * from users: SQLSTATE[HY000] [1045] 用户 &#39;root&#39;@&#39;localhost&#39; 访问被拒绝(使用密码:YES) - SQL: select * from users: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) 错误:无法连接。 SQLSTATE[HY000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:YES) - ERROR: Could not connect. SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM