phpMyAdmin #2002 无法登陆MySQL服务器
最近在容器中安装使用phpMyAdmin,登陆的时候提示#2002
错误,详细错误提示:
#2002 - Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory") — 服务器没有响应(或本地服务器的套接字没有正确设置)。
mysqli_real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")
解决 phpMyAdmin #2002 错误
修改phpMyAdmin目录下的libraries/config.default.php
中的$cfg['Servers'][$i]['host']
参数:
$cfg['Servers'][$i]['host'] = 'localhost';
修改为:
$cfg['Servers'][$i]['host'] = '127.0.0.1';
或:
$cfg['Servers'][$i]['host'] = 'mysql|db';
这就可以了。
例如Docker容器链接,链接的时候自动创建容器名的对应/etc/hosts
,单独下载phpMyAdmin源码则需要按照上面的修改。
方法2
上传的phpMyAdmin程序,解压后浏览器中打开地址,类似:
http://ip address OR domain/phpmyadmin/setup/index.php
按照上图中选择,默认语言,默认服务器(就是刚才新建的),换行符(就是程序所在系统环境 Linux/Windows),然后下载。下载下来的是config.inc.php
文件,放在phpMyAdmin目录下就可以了。
config.inc.php
<?php
/*
* Generated configuration file
* Generated by: phpMyAdmin 4.7.3 setup script
* Date: Fri, 11 Aug 2017 01:49:09 +0000
*/
/* Servers configuration */
$i = 0;
/* Server: db [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'db';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
/* End of servers configuration */
$cfg['blowfish_secret'] = '\'%]\\s&kj/SS9P%2[#?KJ\'E$n<YvvE8\\W';
$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。