mysql_connect()“No such file or directory”错误排除

在部署LogAnalyzer时碰到一个mysql_connect()的错误,其实就是php抛出的错误!

mysql_connect()函数:http://www.w3school.com.cn/php/func_mysql_connect.asp

主机环境:PHP5.6.1,Nginx1.4.7,Mysql5.5.40

此时的情况是,查询日志时间就会抛出这个错误,而其他模块,比如添加删除用户等,没有受影响,

执行SQL语句select DeviceReportedTime,FromHost,Message from Syslog.SystemEvents,可以得到正常数据。

那问题基本就是出在了php调用Mysql上了。。。。。。。

开始排错:

1.查找LogAnalyzer中用到mysql_connect()函数的地方:

http://phpcrossref.com/xref/loganalyzer/_functions/mysql_connect.html

共计4处

2.查找LogAnalyzer的config.php中的配置

发现有一处表的名字错了,修改为系统正确的即可,此处只是修改了系统配置文件;

进入数据库,修改Syslog数据库下的表logcon_sources的字段DBTableName为正确值;

3.检验mysql_connect()函数是否正确

(1).创建一个test.php

<span style="font-size:14px;"><?php
$con = mysql_connect("localhost","syslog","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// 一些代码...

mysql_close($con);
?></span>

使用http://localhost:9189/test.php,访问只掉跳出“Could not。。。。。”

2.上一步把问题都确认了,Mysql我也知道UNIX socket的位置

直接进入/etc/php.ini下修改这3个和Mysql相关的套结函数指定位置

<span style="font-size:14px;">mysql.default_socket =/mnt/mydata/mysql.sock
mysqli.default_socket =/mnt/mydata/mysql.sock
pdo_mysql.default_socket=/mnt/mydata/mysql.sock</span>

之后重启php-fpm问题解决

总结一下:

1.网上抄袭回来的代码要细细验证,即使是开源的;

2.出了错,不要到处问人,应该讲程序全部调至debug模式,逐步排除!

时间: 2024-08-04 20:56:27

mysql_connect()“No such file or directory”错误排除的相关文章

解决MAC下PHP连接MYSQL错误Warning: mysql_connect(): No such file or directory in conn.php

今天在mac上用php去连接mysql数据库,出现了 mac PHP Warning:  mysql_connect(): [2002] No such file... 详细例如以下所看到的: DirkMacBook:vote Dirk$ phpunit MyTest.php  Warning: mysql_connect(): No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/myvote/vote/conn.

/etc/rc.d/init.d/iptables: No such file or directory 错误原因

注:本文转载自cnblogs:一天学点的文章</etc/rc.d/init.d/iptables: No such file or directory 错误原因> RedHat Enterprise Linux 7关闭防火墙方法 在之前的版本中关闭防火墙等服务的命令是 1 service iptables stop 2 3 /etc/init.d/iptables stop 在RHEL7中,其实没有这个服务 1 [[email protected] ~]# cat /etc/redhat-re

Failed to connect socket to &#39;/var/run/libvirt/libvirt-sock&#39;: No such file or directory错误处理

redhat7 ERROR    Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory yum -y install avahi systemctl start libvirtd Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory错误处理

win8/win7中使用Git Extensions PuTTy模式提交时 git-credential-winstore.exe&quot;: No such file or directory 错误解决方案

参考:http://www.cnblogs.com/hlizard/p/3627792.html 报错类似以下错误 \"F:/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: "F:/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe": No such file or directory 解决方案

python打包成.exe工具py2exe0-----No such file or directory错误

转自:http://justcoding.iteye.com/blog/900993 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序. py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,win32com client和server,和其它的独立程序.py2exe是发布在开源许可证下的. 二.安装py2exe 从h

QT关于“fatal error: QApplication: No such file or directory“错误解决

建立QT工程时,由于QT4兼容性的问题,出现关于“fatal error: QApplication: No such file or directory“错误 解决办法也很简单:在工程的 .pro file: 添加:QT += core gui widgets 如果还没有用,则 将#include <QApplication>换成#include <QtWidgets/QApplication> 例如: #include <QtWidgets/QApplication>

php的mysqli_connect函数显示 No such file or directory错误以及localhost换成127.0.0.1执行成功

linux环境-php7-MariaDB5.5.60 (新安装的php7,执行php -m 显示有mysqli模块,php.ini没有改其它) 测试代码为: <?php //~ echo date('Y-m-d H:i:s',time()); $link_id = mysqli_connect('localhost','root',''); if($link_id) { echo 'ok'; } else { echo mysqli_connect_error(); } ?> 网页运行时显示

Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)

说明: 本文主要内容参考: Mac下PHP连接MySQL报错"No such file or directory"的解决办法, 并进行个人补充 1. 运行环境: Mac OS X 10.11.4 (Mac 已经自带 Apache, PHP) 2. 相关文件夹:  /etc/apache2/     ##Apache 配置文件夹  /Library/WebServer/Documents/    ##Apache 默认站点  /usr/local/mysql-5.7.11-osx10.9-x86_

Qt5编译项目出现GL/gl.h:No such file or directory错误

编译在Ubuntu12.04下安装了Qt5.1.1,在编译工程的时候出现了如下错误:“GL/gl.h:No such file or directory”,查了一下资料发现这个问题由于系统中没有安装OpenGL库导致的, 使用命令行安装OpenGL库及其工具:apt-get install libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev 即可.