【问题标题】:mysql connection refused and mysql no such file or directorymysql连接被拒绝并且mysql没有这样的文件或目录
【发布时间】:2014-06-05 04:14:55
【问题描述】:

只需连接mysql服务器,用户名密码和主机都正确。

仍然 mysql_error() 抛出以下错误:

Warning: mysql_connect(): No such file or directory in 
save.php on line 6
No such file or directory

当我将它从 'localhost' 更改为 '127.0.0.1' 时,它给出了错误:

Warning: mysql_connect(): Connection refused in 
save.php on line 6
Connection refused

对于同一主机上的 wordpress 网站,相同的连接正常工作。

当我输入错误的密码时,mysql会抛出密码不存在的错误

什么意思?

[更新]

我检查了我的 phpinfo() 和

mysql.default_socket    no value    no value

default_host、用户、密码等相同

我试过了

ini_set("mysql.default_socket","/var/run/mysqld/mysqld.sock");

正如 php.ini 中提到的,但没有运气。

它再次为 wordpress 以前的安装工作,它的 wp_config 具有相同的 mysql 访问权限。对于错误的密码,有时会抛出“密码不存在”

【问题讨论】:

标签: php mysql sockets connection


【解决方案1】:

即使我也遇到过类似的问题。请试试这个,希望它对你有用。使用 mysqli 而不是 mysql

// Create connection

$domain   = "localhost";  // or yourdomainname.com
$username = "root";       // db username
$password = "pass123";    // db password
$dbName   = "gymchalo";   // db name

$con = mysqli_connect($domain,$username,$password,$dbName);

// Check connection
if (mysqli_connect_errno()){

    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    die('Mysql connection error');
}else{
    echo "Connection Established";
}

【讨论】:

  • 警告:mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in save.php on line 5 Failed to connect to MySQL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)Mysql连接错误
猜你喜欢
  • 2015-11-02
  • 2018-09-30
  • 2011-02-16
  • 2013-05-04
  • 2017-12-12
  • 2010-12-13
相关资源
最近更新 更多