简体   繁体   English

警告:mysql_connect():无法通过套接字“ /tmp/mysql.sock”连接到本地MySQL服务器(2)

[英]Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

everyone. 大家。 I'm a student and very inexperience newbie with PHP . 我是一名学生,对PHP经验不足。 Before you mark this as irrelevant or duplicate or anything. 在您将此标记为无关或重复或任何东西之前。 Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla 请听我说,我需要连接到学校的主机以测试我的代码,我已经使用notepad ++文本编辑器安装了XAMPP,phpmyadmin 4.0.4.1,PHP5.4.19和FTP WinSCP,该程序类似于filezilla

  • uploaded all the files to the server side public html and tried to run the file in browser by using: my_school_link/my_username/ 将所有文件上传到服务器端公共html,并尝试通过以下方式在浏览器中运行该文件:my_school_link / my_username /

and I have this error 我有这个错误

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on line 3 and this is my connect.php file. 警告:mysql_connect():无法通过第3行/my_full_filepath..../connect.php中的套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器,这是我的connect.php文件。

<?php

mysql_connect('host_name', 'user_name', 'password');

mysql_select_db('my_database_name');

?>

I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock* 我找不到我的/tmp/mysql.sock,*我在xampp文件夹中有tmp文件夹,但是在里面找不到mysql.sock *

and I have tried the following 我尝试了以下

  • view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers) 查看关于此事的几乎所有帖子(我不明白在说什么,您确实尝试了一些建议和答案)
  • have entered the correct hostname, username and password 输入了正确的主机名,用户名和密码
  • run as admin 以管理员身份运行
  • checked if mysql is running ( it is so is Apache) 检查mysql是否正在运行(Apache也是如此)
  • MySQL socket specified in php.ini was never edited so it is in default mode 从未编辑php.ini中指定的MySQL套接字,因此它处于默认模式
  • cant locate mysql config file, or my.cnf, or etc folder 无法找到mysql配置文件或my.cnf等文件夹

What could the problem be? 可能是什么问题? Please if anyone could help me, please tell me what's wrong. 如果有人可以帮助我,请告诉我怎么了。

Please provide a step-by-step guide. 请提供逐步指南。 and file extensions if need to save files.... 和文件扩展名,如果需要保存文件...。

Is there any additional things i can add to help anyone understand my problem better? 我可以添加其他任何内容来帮助任何人更好地理解我的问题吗? if yes, please let me know...this is my last resort so Thank you so very much in advance for any help. 如果是,请让我知道...这是我的不得已,所以非常感谢您的帮助。

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on line 3 and this is my connect.php file. 警告:mysql_connect():无法通过第3行/my_full_filepath..../connect.php中的套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器,这是我的connect.php文件。

This error appear when your mysql server is not running. 当您的mysql服务器未运行时,会出现此错误。 If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.) 如果您在共享主机上,则意味着您的提供者已临时停止了mysql服务器(需要解决一些问题,或进行更新等)。

If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this: 如果您使用的是WAMP或本地计算机,则应检查/etc/my.cnf文件,其中包含以下内容:

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock

Another reason may be that you are using the wrong host name while connect. 另一个原因可能是您在连接时使用了错误的主机名。

Don't use mysql_connect it is deprecated and instead you should use MySqli 不要使用mysql_connect,它已被弃用,而应该使用MySqli

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过套接字&#39;/tmp/mysql.sock&#39;(2)错误连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) error Mac 上的 Django + XAMPP(2002,“无法通过套接字&#39;/tmp/mysql.sock&#39;(2)连接到本地 MySQL 服务器”) - Django + XAMPP on Mac (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") MySQL服务器崩溃且无法启动-无法通过套接字&#39;/tmp/mysql.sock连接到本地MySQL服务器 - MySQL Server crashes and fails to start - Can't connect to local MySQL server through socket '/tmp/mysql.sock 无法连接:无法通过套接字“ /var/lib/mysql/mysql.sock”连接到本地MySQL服务器(2) - Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Mac Terminal / MySQL配置问题| 错误2002(HY000):无法通过套接字&#39;/tmp/mysql.sock&#39;连接到本地MySQL服务器(2) - Mac Terminal/ MySQL configuration issues | ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) MAMP “Apache 无法启动,因为端口正在使用中。” 和“无法通过 /tmp/mysql.sock 连接到本地 MySQL 服务器 - MAMP “Apache couldn't be started because port is in use.” AND "Can’t connect to local MySQL server through /tmp/mysql.sock err_connection_timed_out 和 PHP 警告:mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' - err_connection_timed_out and PHP Warning: mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' Wordpress中的MYSQL连接问题-无法通过套接字&#39;/var/lib/mysql/mysql.sock&#39;连接到本地MySQL服务器(2) - Issue with MYSQL connection in Wordpress - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) mysql连接错误:无法通过套接字&#39;/var/lib/mysql/mysql.sock&#39;连接到本地MySQL服务器(2)Godaddy Cpanel - mysql connection error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Godaddy Cpanel 警告:mysql_connect():[2002]中没有这样的文件或目录(试图通过unix:///tmp/mysql.sock连接) - Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM