php – 用户’root’@ localhost mysql错误1045拒绝访问

我是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:
<?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.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...