mysql_connect():没有这样的文件或目录 [英] mysql_connect(): No such file or directory

查看:320
本文介绍了mysql_connect():没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在旧的RedHat7上安装了MySQL服务器(版本3.23.58).由于依赖关系,我无法安装更新的MySQL版本.我无法在此RedHat服务器上更新库.

I have just installed a MySQL server (version 3.23.58) on an old RedHat7. I cannot install a more recent MySQL version because of the dependencies. I cannot update librairies on this RedHat server.

但是,我在使用PHP连接到数据库时遇到问题.首先,我使用了PDO,但是我意识到PDO与MySQL 3.23不兼容...

However, I have a problem connecting to the database with PHP. First I used PDO but I realized that PDO was not compatible with MySQL 3.23...

所以我用了mysql_connect().现在,我出现以下错误:

So I used mysql_connect(). Now I have the following error:

Warning: mysql_connect(): No such file or directory in /user/local/apache/htdocs/php/database.php on line 9
Error: No such file or directory

我的代码是:

$host = 'localhost';
$user = 'root';
$password = '';
$database = 'test';
$db = mysql_connect($host, $user, $password) or die('Error : ' . mysql_error());
mysql_select_db($database);

我两次检查数据库是否存在以及登录名和密码是否正确.

I checked twice that the database exists and the login and password are correct.

这很奇怪,因为该代码在使用Wampp的Windows PC上可以正常工作.我不知道问题出在哪里.

This is strange because the code works fine on my Windows PC with Wampp. I cannot figure out where the problem comes from.

有什么主意吗?

推荐答案

是的,您不能那样连接!

Yes you can not connect like that!

@PLB和@jammypeach mysqli在v4.1之后,他正在使用v3 :) 如果您真的想提供帮助,请阅读规格书!

@PLB and @jammypeach mysqli is after v4.1, he is using v3 :) Guys read the specs, if you want really to help!

您无法连接,因为您的套接字文件有点错误.现在,我记得以前的RH曾遇到过此问题. 您的套接字可能是/var/mysql/mysql.sock或/tmp/mysql.sock,但是一个或多个应用程序正在寻找另一个.

You can't connect, because your socket file is a bit wrong. I remember now that the old RH had this issue before. Your socket is probably as /var/mysql/mysql.sock or /tmp/mysql.sock but one or more apps are looking for the other.

如果您使用的是/tmp/mysql.sock,但没有使用/var/mysql/mysql.sock,则应该:

If yours is /tmp/mysql.sock but no /var/mysql/mysql.sock you should:

cd /var 
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

如果您拥有/var/mysql/mysql.sock但没有/tmp/mysql.sock,则:

If you have /var/mysql/mysql.sock but no /tmp/mysql.sock then:

cd /tmp
ln -s /var/mysql/mysql.sock mysql.sock

您将需要权限才能进行更改.只是sudo,如果需要的话,在上面的命令之前!

You'll need permissions to make the changes. Just sudo, if needed before the commands above!

另一个解决方案(更简单):

ANOTHER SOLUTION (easier):

创建文件并调用phpinfo();寻找'mysql.default_socket';或'pdo_mysql.default_socket'; 打开My.ini或My.cnf查找套接字值,例如套接字=/tmp/mysql.sock 打开您的php.ini文件(也可以在phpinfo()页面上找到已加载的配置文件"),然后将所有出现的错误套接字位置从MySQL更改为正确的套接字位置.

Create file and call phpinfo(); Look for 'mysql.default_socket'; or 'pdo_mysql.default_socket'; Open My.ini or My.cnf find the socket value e.g. socket=/tmp/mysql.sock Open your php.ini file (which is also found on your phpinfo() page as ‘Loaded Configuration File‘) and change all the occurrences of the incorrect socket location to the correct socket location from MySQL.

另一个解决方案(最简单): 用于PDO的DSN:

ANOTHER SOLUTION (easiest): DSN for PDO:

mysql:unix_socket=/tmp/mysql.sock;dbname=...

mysql_connect:

mysql_connect:

$db = mysql_connect('localhost:/tmp/mysql.sock', ...

您的系统在安全性方面确实很恐怖,如果您托管敏感数据,我会升级到最新版本.

Your system is really scary when it comes to security, if you're hosting sensitive data, I'd upgrade to the latest versions.

----更新----

---- UPDATE ----

Aaahhhh PHP 5.0和MySQL 3.23:)

Aaahhhh PHP 5.0 and MySQL 3.23 :)

PHP 5打包了一个mysql客户端,无法连接到版本低于4.1的MySQL数据库. 从4.1版开始,MySQL使用一种新的密码散列方式,该方式与4.1之前的数据库不兼容.您配置所连接的服务器是3.23版.因此,您需要获得更高版本的MySQL.抱歉,您的情况没有其他实用的解决方案.如果是您,则将升级整个系统并安装最新的OS版本,如果必须的话,我将选择Debian和PHP和MySQL的最新稳定版本.

PHP 5 has a mysql client packaged that cannot connect to a MySQL database less than version 4.1. Starting with version 4.1, MySQL uses a new way of password hashing that is not compatible with pre-4.1 databases. The server your configuration is connecting to is version 3.23. So you need to get yourself a higher version of MySQL. Sorry, but there is no other practical solution for your case. If I was you, I'd upgrade the whole system and install the most recent OS version, if I had to I'd go with Debian and the most recent stable versions of PHP and MySQL.

这篇关于mysql_connect():没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆