mysqli::real_connect(): (HY000/2002): Connection refused

参考文章:https://www.louishe.com/2019/10/28/doc-5925.html

mysqli::real_connect(): (HY000/2002): Connection refused
 使用配置文件中定义的控制用户连接失败。
 mysqli::real_connect(): (HY000/2002): Connection refused

解决办法:

第一步:按照官方文档设置一次密码,设置参考 http://localhost/dashboard/faq.html

How can I make my XAMPP installation more secure?

By default, XAMPP has no passwords set and it is not recommended to run XAMPP with this configuration as it is accessible to others.

Simply type the following command (as root) to start a simple security check:

sudo /opt/lampp/lampp security

Now you should see the following dialog on your screen:

XAMPP: Quick security check...
XAMPP: MySQL is accessable via network.
XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] yes
XAMPP: Turned off.
XAMPP: Stopping MySQL...
XAMPP: Starting MySQL...
XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Setting new MySQL pma password.
XAMPP: Setting phpMyAdmin's pma password to the new one.
XAMPP: MySQL has no root passwort set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Write the passworde somewhere down to make sure you won't forget it!!!
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Setting new MySQL root password.
XAMPP: Setting phpMyAdmin's root password to the new one.
XAMPP: The FTP password for user 'nobody' is still set to 'lampp'.
XAMPP: Do you want to change the password? [yes] yes
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Reload ProFTPD...
XAMPP: Done.

(1) Setting a password will protect the XAMPP demo pages (http://localhost/xampp/) using this password. The user name is ‘lampp’!

After running this command, your XAMPP installation should be more secure.

第二步:

把/opt/lampp/phpmyadmin路径下的config.inc.php文件,使用config.sample.inc.php文件代替。即把原先的 config.inc.php 文件备份,把 config.sample.inc.php 修改成 config.inc.php 。

config.sample.inc.php :

*******
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
******

完成!

推荐阅读

  1. 如何在 Ubuntu 20.04 上使用 Apache (LAMP) 安装 phpMyAdmin
  2. 如何在 Ubuntu 20.04 服务器/桌面上安装 LAMP 堆栈
  3. Ubuntu20.04 XAMPP(Apache) 部署免费 Let’s Encrypt 证书
  4. ubuntu XAMPP启动、停止、重启等常用命令
  5. phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接
  6. 如何在Ubuntu 18.04上安装Apache\MySQL和PHP
  7. Navicat连接ubuntu上MySQL报错:2003-Can’t connect to MySql server on ‘x.x.x.x'(10061 “Unknown error”)
  8. 如何在Ubuntu 18.04操作系统上安装MySQL?

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注