我在一台WIN03的服务器上安装了mysql,新建了一个数据库,然后新建账户,开启远程连接,我可以通过第三方的软件navicat链接,能成功连接,并能操作,但我通过php写好的代码链接的时候就出错了
链接代码如下
<?php
$hostname="ip:1234";//端口我修改过了
$username="myloginusername";
$password="myloginpassword";
$dbname="thedatabase";
$conn=mysql_connect($hostname,$username, $password);
mysql_select_db($dbname,$conn);$info=$_POST['info'];
$exec="insert into thetable (info) values ('".$info."')";
       $result=mysql_query($exec) or die(mysql_errno.'-'.mysql_error());
       echo  " <Script>location.replace('ok.php'); </Script> "; 
       exit();
?>
提示出错如下Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in /home/content/17/5288617/html/
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/17/5288617/html/

mysql_errno-Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)请问这个问题该如何解决呢?

解决方案 »

  1.   

    http://wenda.sogou.com/question/31182893.html
    http://zhidao.baidu.com/question/44369444
    http://forums.mysql.com/read.php?52,151255,156258
    http://www.xishuiw.com/info/2009-3/2009-3-3-16440.htm
    http://zhidao.baidu.com/question/87870784遇到问题多用搜索引擎
      

  2.   

    谢谢,但上面的,我都已经是GOOGLE过,就是尝试过了那么多方法,还是不行,所以才提问的
      

  3.   

    /var/lib/mysql/mysql.sock  这种socket在windows不支持,换成internet域
      

  4.   

    mysql安装在win,PHP安装在哪里啊?不是同一台电脑吗?
    WINDOWS怎么会有这样的路径呢?'/var/lib/mysql/mysql.sock' 是不是PHP的配置有问题?有个指定mysql.sock的配置,是不是错了?
      

  5.   

    PHP页面是放在另外一个LINUX的电脑上,和数据库不是同一台电脑
      

  6.   

    先telnet 你的MYSQL端口看能否进入,如果进入那就检测你PHP代码,否则检测网络环境(比如防火墙,端口限制之类的)以及帐户信息
      

  7.   

    装个phpmyadmin连接一下试试,看能不能连接上。