将HeidiSQL远程数据库设为XAMPP数据库的配置问题咨询
Hey there, let's break down this "No connection could be made because the target machine actively refused it." error you're hitting—this usually points to either a network/remote database issue, or a subtle config tweak needed in your PHP/Apache setup, even though it worked seamlessly before. Let's walk through the key checks and fixes step by step:
先排除远程数据库端的基础问题
This error isn't always tied to your XAMPP setup. First rule out external factors:- Re-test the connection with HeidiSQL to confirm the remote database service is running, its default port (usually 3306 for MySQL/MariaDB) isn't blocked by a firewall, and your machine's IP is added to the remote database's access whitelist (critical for cloud-hosted databases).
- On your XAMPP machine, run a port connectivity test via command line: use
telnet [remote-db-ip] 3306(Windows) ornc -zv [remote-db-ip] 3306(Linux/macOS). If this fails, the problem lies with the remote database or network, not your local Apache/PHP config.
检查PHP数据库扩展配置(php.ini)
Even if you didn't need to modify this before, XAMPP updates or accidental config resets can disable necessary extensions:- Locate your XAMPP php.ini file (typically at
xampp/php/php.ini), open it, and search for database-specific extensions:- For MySQL/MariaDB, look for
extension=mysqliandextension=pdo_mysql—make sure the leading semicolon (;) is removed (this uncomments the line and enables the extension). - For other databases like PostgreSQL, find and uncomment
extension=pgsqlor its equivalent.
- For MySQL/MariaDB, look for
- Save the file and restart Apache. Verify the extension is loaded by creating a
phpinfo.phpfile with<?php phpinfo(); ?>, accessing it via your browser, and searching for the extension name (e.g., "mysqli").
- Locate your XAMPP php.ini file (typically at
排查Apache的安全/网络限制
In rare cases, Apache modules can block outgoing database connections:- If you have
mod_securityenabled, temporarily disable it by commenting outLoadModule security2_module modules/mod_security2.soin yourhttpd.conffile, then restart Apache. If the connection works after this, you'll need to adjust mod_security rules to allow traffic to your remote database port. - Ensure your local machine's firewall isn't blocking Apache from initiating outgoing connections to the remote database's port.
- If you have
Double-check your database connection code
Even if you swear you didn't touch it, accidental tweaks can happen:
Confirm your connection code uses the correct remote IP, port, credentials, and database name. For example:$conn = mysqli_connect('192.168.1.100', 'db_user', 'db_pass', 'your_db', 3306);Make sure you're not using
localhostinstead of the remote IP, and the port matches what the remote database is listening on.
If none of these steps resolve the issue, check if your XAMPP/PHP version was recently updated—newer PHP versions sometimes enforce stricter connection requirements (like mandatory SSL if the remote database has it enabled, but your code isn't configured to use it).
内容的提问来源于stack exchange,提问作者Tolure

