作者:阿宝宝86 | 来源:互联网 | 2023-05-18 05:10
我是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
请告诉我,这里出了什么问题.
解决方法:
在浪费了大部分时间来解决这个问题之后,事实证明我所要做的就是提供非localhost主机名.我不知道为什么(允许用户从任何主机连接),但它的工作原理!
root@base:~# mysql -u username -h hostname -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
在PHP中:
Test 1807:
$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.