我是 PHP 新手。执行我的应用程序时出现以下错误:
在phpMyadmin中代码是这样的
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
因为我已经备份了,所以我把上面的代码改成了
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'Pass123';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
现在我得到以下错误
Access denied for user 'root'@'localhost' (using password: YES) MySQL Error # :1045
请让我知道这里出了什么问题。
最佳答案
在这个问题上浪费了大部分时间后,我发现我所要做的就是提供非本地主机名。我不知道为什么(允许用户从任何主机连接),但它有效!
root@base:~# mysql -u username -h hostname -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
在 PHP 中:
Test 1807:
<?php
$username = "username";
$password = "password";
$hostname = "actualhostnamenotlocalhost";
$con = mysqli_connect($hostname, $username, $password);
// Check connection
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($con);
?>
OK.
关于php - 用户 'root' @localhost mysql 错误 1045 的访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5547288/