php mysqli_real_connect(): (HY000/2002): 没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41881123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysqli_real_connect(): (HY000/2002): No such file or directory
提问by luigi
mysqli_real_connect(): (HY000/2002): No such file or directory
PhpMyAdmin error on MacOS. I want answer I really have no idea what I need to do to resolve this.
MacOS 上的 PhpMyAdmin 错误。我想要答案我真的不知道我需要做什么来解决这个问题。
回答by naiz0
change localhost to 127.0.0.1 in /etc/phpmyadmin/config.inc.php
在 /etc/phpmyadmin/config.inc.php 中将 localhost 更改为 127.0.0.1
$cfg['Servers'][$i]['host'] = '127.0.0.1';
The reason for this is that pma tries to connect to the mysql.socket if you use localhost. If you use 127.0.0.1 PMA makes a TCP connection which should work.
这样做的原因是如果您使用 localhost,pma 会尝试连接到 mysql.socket。如果您使用 127.0.0.1 PMA 建立一个应该可以工作的 TCP 连接。
回答by faruq ah
i'm trying this before
我以前试过这个
cd /opt/lampp/phpmyadmin
cd /opt/lampp/phpmyadmin
then
然后
gedit config.inc.php
gedit config.inc.php
find this,
找到这个,
$cfg['Servers'][$i]['host'] =
if there is localhost
change it to 127.0.0.1
如果有localhost
改变它127.0.0.1
Note : if there is '//' remove // before
$cfg['Servers'][$i]['host']
注意:如果有 '//' 删除 // 之前
$cfg['Servers'][$i]['host']
I checked again http://localhost/phpmyadmin/
我再次检查 http://localhost/phpmyadmin/
mysqli said :
mysqli 说:
"phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server."
“phpMyAdmin 尝试连接 MySQL 服务器,服务器拒绝连接。您应该检查配置中的主机、用户名和密码,并确保它们与 MySQL 服务器管理员提供的信息相对应。”
i'm opening again config.inc.php
and i found
我再次打开config.inc.php
,我发现
$cfg['Servers'][$i]['password'] =
Fill the password with your password
用您的密码填写密码
It worked for me. It may work for you too.
它对我有用。它也可能对你有用。
回答by Siraj Alam
phpmyadmin 2018 October
phpmyadmin 2018 年 10 月
Locate config.sample.inc.php
定位 config.sample.inc.php
Change
改变
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
into
进入
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
Save.
节省。
Then rename file and remove samplefrom the name.
然后重命名文件并从名称中删除示例。
回答by Abdulla Nilam
Maybe your SQL server has been stopped
也许您的 SQL 服务器已停止
sudo /etc/init.d/mysql start
or
或者
sudo service mysqld start
and useservice mysql status
to check status
并用于service mysql status
检查状态
回答by Randika Vishman
mysqli_connect(): (HY000/2002): No such file or directory
mysqli_connect(): (HY000/2002): 没有那个文件或目录
Background:
背景:
I was just wanted to run some PHPUnit tests on my Mac, using Terminal. Some of the classes I wanna test was having to connect MySQL DB which was created and managed by PHPMyAdmin, and the web app I was working was working fine in the localhost. So when I ran that testcases I got the following error on my terminal:
我只是想使用终端在我的 Mac 上运行一些 PHPUnit 测试。我想要测试的一些类必须连接由 PHPMyAdmin 创建和管理的 MySQL 数据库,而我正在使用的 Web 应用程序在本地主机中运行良好。因此,当我运行该测试用例时,我的终端出现以下错误:
mysqli_connect(): (HY000/2002): No such file or directory
Solution:
解决方案:
So with the itchiness I had to resolve it and run my test I searched in few SO Q&A threads and tried out. And a combination of changes worked for me.
因此,由于我不得不解决它并运行我的测试,我在几个 SO Q&A 线程中进行了搜索并进行了尝试。一系列变化对我有用。
- Locate your
config.inc.php
file which relates to PHPMyAdmin. - Locate the line
$cfg['Servers'][$i]['host']
mostly this line might have been commented out by default, if so please uncomment it. - And replace that line with following:
- 找到
config.inc.php
与 PHPMyAdmin 相关的文件。 - 主要定位到
$cfg['Servers'][$i]['host']
该行,默认情况下该行可能已被注释掉,如果是这样,请取消注释。 - 并用以下内容替换该行:
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
- Save it and restart the MySQL Database from your XAMPP control panel (manager-osx).
- Change your
$host
parameter value in themysqli_connect()
method to following:
- 保存并从 XAMPP 控制面板 (manager-osx) 重新启动 MySQL 数据库。
$host
将mysqli_connect()
方法中的参数值更改为以下内容:
$_connection = mysqli_connect(**"localhost: 3306"**, $_mysql_username, $_mysql_password, $_database);
$_connection = mysqli_connect(**"localhost: 3306"**, $_mysql_username, $_mysql_password, $_database);
Note:This 3306
is my MySQL port number which is its default. You should better check what's your actual MySQL Port number before going to follow these steps.
注意:这3306
是我的默认 MySQL 端口号。在执行这些步骤之前,您最好检查一下您的实际 MySQL 端口号是多少。
And that's all. For me only these set of steps worked and nothing else. I ran my Unit Tests and it's working fine and the DB data were also updated properly according to the tests.
就这样。对我来说,只有这些步骤有效,没有别的。我运行了我的单元测试,它工作正常,数据库数据也根据测试正确更新。
Why this works:
为什么这样做:
The closest reason I could have found is that it works because sometimes the mysqli_connect
method requires a working socket(IP Address of the DB Host along with the Port number) of the database. So if you have commented out the $cfg['Servers'][$i]['host'] = '127.0.0.1';
line or have set 'localhost' as the value in it, it ignores the port number. But if you wanna use a socket, then you have to use '127.0.0.1' or the real hostname. (for me it appears to be regardless of the default port number we really have, we have to do the above steps.) Read the following link of PHPMyAdminfor further details.
我能找到的最接近的原因是它可以工作,因为有时该mysqli_connect
方法需要数据库的工作套接字(DB 主机的 IP 地址以及端口号)。因此,如果您已注释掉该$cfg['Servers'][$i]['host'] = '127.0.0.1';
行或将 'localhost' 设置为其中的值,它将忽略端口号。但是,如果您想使用套接字,则必须使用“127.0.0.1”或真实主机名。(对我来说,这似乎与我们真正拥有的默认端口号无关,我们必须执行上述步骤。)阅读PHPMyAdmin的以下链接以获取更多详细信息。
Hope this might be helpful to somebody else out there.
希望这可能对其他人有所帮助。
Cheers!
干杯!
回答by AbelSurace
First of all, make sure the mysql service is running:
首先,确保mysql服务正在运行:
ps elf|grep mysql
you will see an output like this if is running:
如果正在运行,您将看到这样的输出:
4 S root 9642 1 0 80 0 - 2859 do_wai 23:08 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/tomcat-machine.local.pid
4 S mysql 9716 9642 0 80 0 - 200986 poll_s 23:08 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/tomcat-machine.local.err --pid-file=/var/lib/mysql/tomcat-machine.local.pid
then change localhost to 127.0.0.1 in config.inc.php
然后在 config.inc.php 中将 localhost 更改为 127.0.0.1
$cfg['Servers'][$i]['host'] = '127.0.0.1';
The default password for "root" user is empty "" do not type anything for the password
“root”用户的默认密码为空“”不要输入任何密码
If it does not allow empty password you need to edit config.inc.php again and change:
如果它不允许空密码,则需要再次编辑 config.inc.php 并更改:
$cfg['Servers'][$i]['AllowNoPassword'] = true;
The problem is a combination of config settings and MySQL not running. This was what helped me to fix this error.
问题是配置设置和 MySQL 未运行的组合。这是帮助我修复此错误的原因。
回答by Ketan Yekale
I fixed the issue today using the steps below:
我今天使用以下步骤解决了这个问题:
If config.inc.php does not exists in phpMyadmin directory Copy config.sample.inc.php to config.inc.php.
Add socket to
/* Server parameters */
$cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';
Save the file and access phpmyadmin through url.
如果 phpMyadmin 目录中不存在 config.inc.php 将 config.sample.inc.php 复制到 config.inc.php。
将套接字添加到
/* Server parameters */
$cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';
保存文件并通过url访问phpmyadmin。
If you are using the mysql 8.0.12 you should use legacy password encryption as the strong encryption is not supported by the php client.
回答by Stephen Chen
I faced this problem on CentOS.
我在CentOS上遇到了这个问题。
First I try this
首先我试试这个
sudo service mysql restart
Then error shows up
然后出现错误
Redirecting to /bin/systemctl restart mysql.service
Failed to restart mysql.service: Unit not found.
Then I Found this
然后我发现了这个
Command this solve my problem
命令这解决了我的问题
systemctl start mariadb.service
回答by demenvil
Try just
试试吧
sudo service mysql restart
须藤服务 mysql 重启
It's work for me
这对我有用
回答by lortschi
I had the same problem. In my /etc/mysql/my.cnf
was no path more to mysqld.sock
defined. So I started a search to find it with: find / -type s | grep mysqld.sock
but it could not be found.
I reinstalled mysql with: apt install mysql-server-5.7
(please check before execute the current sql-server-version).
我有同样的问题。在我的/etc/mysql/my.cnf
道路上没有更多的mysqld.sock
定义。所以我开始搜索以找到它:find / -type s | grep mysqld.sock
但找不到。我重新安装了 mysql :(apt install mysql-server-5.7
请在执行当前的 sql-server-version 之前检查)。
This solved my problem.
这解决了我的问题。