[英]“Can't connect to local MySQL server through socket” on linux server
I'm having a hard time getting my website connected to the mySQL database on host. 我很难将我的网站连接到主机上的mySQL数据库。 However, when I was running my website on the PC by Apache it was connecting smoothly. 但是,当我在PC上运行我的网站时,它正在顺利连接。 The snippet I'm using to connect is: 我用来连接的片段是:
<?php
$conn_error = 'Could not connect';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'firstdatabase';
if(!mysql_connect($mysql_host,$mysql_user,$mysql_pass)|| !@mysql_select_db($mysql_db)){
die($conn_error);
}else{
//echo 'Connected';
}
?>
And it gives me the following error when I try to connect to mysql on the web host: 当我尝试连接到Web主机上的mysql时,它给了我以下错误:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server
through socket 'MySQL' (2) in /home/umudo/public_html/connectserver.inc.php on line 10
I searched through the web for finding a solution but couldn't find any exact example of this. 我在网上搜索以查找解决方案,但找不到确切的示例。
Help: http://dev.mysql.com/doc/refman/5.0/en/connecting.html 帮助: http : //dev.mysql.com/doc/refman/5.0/en/connecting.html
Says: 说:
On Unix, MySQL programs treat the host name localhost specially , in a way that is likely different from what you expect compared to other network-based programs. 在Unix上,MySQL 程序特别对待主机名localhost ,与其他基于网络的程序相比,它可能与您期望的方式不同。 For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. 为了连接到本地主机,MySQL程序尝试使用Unix套接字文件连接到本地服务器。
So you have to 所以你必须这样做
Second method is better - using sockets for local connections is better than TCP/IP (better performance), but you may have no privileges to mysql configuration on that server. 第二种方法更好 - 使用套接字进行本地连接比TCP / IP(性能更好)更好,但是您可能没有权限在该服务器上进行mysql配置。
尝试像apt-get install phpmyadmin中一样安装phpmyadmin或php5-mysql。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.