php 警告:mysqli_connect():(HY000/1045):用户'root'@'localhost'的访问被拒绝(使用密码:NO)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30975475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:09:59  来源:igfitidea点击:

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

phpmysqlmysqli

提问by Zeshan

PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in G:\PleskVhosts\peacewithoutlimits.org\httpdocs\admin\includes\connect.php on line 8

PHP 警告: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in G:\PleskVhosts\peacewithoutlimits.org\httpdocs\admin\includes\connect.php 8号线

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "peace";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

?>

回答by Gideon Appoh

Access denied means that the authentication failed. That means there is an invalid username or password combination. For SQL, it's obvious that the user can be root. So please go to your phpMyAdmin and check from the users tab. You may find out the password set on the root account. And usually online databases are always password protected.

访问被拒绝意味着身份验证失败。这意味着存在无效的用户名或密码组合。对于SQL,很明显用户可以是root。因此,请转到您的 phpMyAdmin 并从用户选项卡中查看。您可能会发现在 root 帐户上设置的密码。通常在线数据库总是受密码保护。

回答by Collin Kiprono

the root password could be empty but the option selected is password. At the change password button in your admin, there's a radio button with two option ( 1. No password and 2. Password) Most of the time the password option is selected therefore requires/assumes you have a password. Just get to the options and change to No password option. Worked for me

root 密码可以为空,但选择的选项是密码。在管理员的更改密码按钮上,有一个带有两个选项的单选按钮(1. 无密码和 2. 密码)大多数情况下选择密码选项,因此需要/假设您有密码。只需进入选项并更改为无密码选项。为我工作