Home  >  Article  >  Backend Development  >  郁闷有关问题,非常的郁闷

郁闷有关问题,非常的郁闷

WBOY
WBOYOriginal
2016-06-13 11:18:41927browse

郁闷问题,非常的郁闷。
有台服务器 linux+apache+mysql+php 另安装了phpmyadmin
使用phpmyadmin可以正常访问服务器
可是用我自己写的php
连接数据库说目标机器积极拒绝。无法连接……。

    $username = "Test";   <br />    $psword = "123456";  <br />    $hostname = "10.12.18.27";  <br />    $dbName = "TestDb"; <br /><br />    $server_link = mysql_connect("$hostname","$username","$psword")  <br />            or die("Can't connect to server" . mysql_error()); 

这句话就出问题…………。娘亲啊,没天理
用root 或Test账号,在phpmyadmin都可以正常登陆.
唯一的差别就是phpmyadmin在服务器上面
我的php代码在我电脑上面(Apache+php+win7)
再说Test账号,什么远程登陆,任意位置登陆功能全打开了的……


------解决方案--------------------
没有开放mysql远程连接的权限
------解决方案--------------------
你可以用sqlyog或者命令行去连接看看。看能不能连接成功。
------解决方案--------------------
mysql 数据库里的 user 表的 host 项,从 localhost 改称 % 
或者新加条记录,host 项为 你本地的ip地址,并授权
重启mysql服务

规矩的做法:
使用 GRANT 命令
你想myuser使用mypassword从任何主机连接到mysql服务器的话。 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn