免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2902 | 回复: 2
打印 上一主题 下一主题

CentOS系统安装了LNMP包之后再装php-mysql,出现socket错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-02 09:49 |只看该作者 |倒序浏览
本帖最后由 imgotop 于 2010-05-02 09:55 编辑

我的CentOS装的是LNMP0.4这个一键安装包

但是用crontab运行php脚本的时候出现错误提示:
PHP Fatal error:  Call to undefined function mysql_connect()

http://www.chinalinuxpub.com/bbs/archive/index.php/t-2221.html
这篇文章说是因为mysql库没有编译进去

所以我就运行 yum install php-mysql 命令

但是安装了这个之后出现错误

PHP Warning:  mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
PHP Warning:  mysql_query(): A link to the server could not be established in

运行yum install php-mysql的时候出现这个:
  1. Running Transaction
  2.   Installing     : perl-DBI                                                 1/4
  3.   Installing     : mysql                                                    2/4
  4. warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
  5.   Installing     : php-pdo                                                  3/4
  6.   Installing     : php-mysql                                                4/4
复制代码
/etc/my.cnf.rpmnew的内容如下
  1. [mysqld]
  2. datadir=/var/lib/mysql
  3. socket=/var/lib/mysql/mysql.sock
  4. user=mysql
  5. # Default to using old password format for compatibility with mysql 3.x
  6. # clients (those using the mysqlclient10 compatibility package).
  7. old_passwords=1

  8. # Disabling symbolic-links is recommended to prevent assorted security risks;
  9. # to do so, uncomment this line:
  10. # symbolic-links=0

  11. [mysqld_safe]
  12. log-error=/var/log/mysqld.log
  13. pid-file=/var/run/mysqld/mysqld.pid
复制代码
/etc/my.cnf 中关于socket的内容如下:
  1. # The following options will be passed to all MySQL clients
  2. [client]
  3. #password        = your_password
  4. port                = 3306
  5. socket                = /tmp/mysql.sock

  6. # Here follows entries for some specific programs

  7. # The MySQL server
  8. [mysqld]
  9. port                = 3306
  10. socket                = /tmp/mysql.sock
复制代码
查看/tmp/mysql.sock 是存在的

而对于/var/lib/mysql/mysql.sock 则根本没有/var/lib/mysql这个目录

运行service mysqld start命令,提示mysqld: unrecognized service

查看/etc/rc.d/init.d 目录,没有找到mysqld


我还利用ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 命令建立了连接

但是都没有用

论坛徽章:
0
2 [报告]
发表于 2010-05-03 00:39 |只看该作者
你执行mysqld_safe命令先把mysql运行起来,然后在php端通过配置ip+port来连接数据库。可能还会遇到mysql没有授权的问题,你再对本机做下授权。通过本地socket访问也是可以的,但配置中的socket项要配成提示的那个路径。估计你还没运行起来mysql,可以找手册把mysql运行起来。

论坛徽章:
0
3 [报告]
发表于 2010-05-04 08:21 |只看该作者
你执行mysqld_safe命令先把mysql运行起来,然后在php端通过配置ip+port来连接数据库。可能还会遇到mysql没有 ...
kafka0102 发表于 2010-05-03 00:39



ln -s /tmp/mysql.sock  /var/lib/mysql/mysql.sock  
命令做链接之后就可以正常运行php程序了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP