[英]Ubuntu Lamp php script with mySQL connection not using Apache
[英]Not able to connect to mysql via php script , but can login to phpmyadmin in LAMP UBUNTU
我试图在ubuntu LAMP中使用PHP连接到mysql。 我可以登录phpmyadmin,但无法使用php代码进行连接。 该代码在XAMPP中运行良好。
我正在使用以下代码
$con=mysql_connect("127.0.0.1","myusername","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
但它显示以下错误
Could not connect: Access denied for user 'root'@'localhost' (using password: YES)
根据问题,有3种(我知道)可行的解决方案。
您需要打开ubuntu中的防火墙,方法是在IPtables中授予访问权限。
/ sbin / iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT现在,我们应该能够从本地计算机登录到服务器了:
mysql -h255.112.324.12 -uroot -pMyPASSWORD
您需要授予对mysql的访问权限: https : //askubuntu.com/questions/159053/mysql-server-not-accessible-from-remote-machine
以根用户身份,用您喜欢的编辑器打开/etc/mysql/my.cnf,查找[mysqld]部分,然后在其中输入bind-address关键字。 通常将其设置为127.0.0.1-更改它以匹配您的“常规” IP地址,保存文件,然后重新加载服务(例如,使用服务mysql restart)
最后但并非最不重要的一点是,您需要在mysql中进行远程访问:
将所有内容授予mydb。*至'MyPASSWORD'标识的root @'%';
来源: http ://web.archive.org/web/20120930214828/http: //chosencollective.com/technology/how-to-enable-remote-access-to-mysql +许多不眠之夜。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.