本文介绍了无法让mysql_connect工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试做一些非常简单的事情 - 连接到

MySQL数据库。这是调用,然后是错误消息。


$ conn = mysql_connect(" localhost"," root","");


警告:mysql_connect():无法通过

socket''/ var / lib / mysql / mysql.sock''(13)连接到本地MySQL服务器
/ b / html / buildhw.php

第13行

失败


我也试过这个主持arg为",但我得到相同的

结果。以root身份登录也没有任何区别。


非常感谢任何帮助。


谢谢,

M. McDonnell

Hi,

I''m trying to do something which should be very simple - connect to the
MySQL database. Here is the call, followed by the error msg.

$conn = mysql_connect("localhost", "root", "");

Warning: mysql_connect(): Can''t connect to local MySQL server through
socket ''/var/lib/mysql/mysql.sock'' (13) in /var/www/html/buildhw.php on
line 13
failed

I''ve also tried this with the host arg as "", but I get the same
result. Logging on as root made no difference either.

Any help would be very much appreciated.

Thanks,
M. McDonnell

推荐答案






你可能想调整你的php.ini for mysql。

寻找[MySQL]然后是这样的行:


;本地MySQL连接的默认套接字名称。如果为空,则使用内置的

; MySQL默认值。

mysql.default_socket =


我怀疑你的mysql已被编译为没有套接字文件

/ TMP /的mysql.sock。事实上,它似乎在/var/lib/mysql/mysql.sock。

快速检查/etc/my.cnf会告诉你它应该在哪里。


-david-



You may want to adjust your php.ini for mysql.
Look for [MySQL] and then the lines like this:

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

I suspect your mysql has been compiled not to have the socket file in
/tmp/mysql.sock. In fact, it appears to be in /var/lib/mysql/mysql.sock.
A quick check of /etc/my.cnf will tell you where it should be.

-david-


这篇关于无法让mysql_connect工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:56