Unable to connect Local mysql (PDOException) in sample WP site on Windows 10

Issue Summary

  1. error message from a particular request in WP site : Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] connexion refused

  2. error message from PhpMyAdmin when trying to connect to Local DB : mysqli::real_connect(): (HY000/2002): Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée

Troubleshooting Questions

  • Does this happen for all sites in Local, or just one in particular?

just for PDO requests. Other DB access ok.
same trubble trying to connect with PhpMyAdmin

  • Are you able to create a new, plain WordPress site in Local and access it in a Browser?



basic sample WP site + “independent Analytics” plugin. ‘geo’ tab in plugin admin page.

concerning PhpMyAdmin : just try to log in to Local database

System Details

  • Which version of Local is being used?

  • What Operating System (OS) and OS version is being used?

    • Windows 10
  • Attached Local php Log.

error.log (5.2 KB)

Security Reminder

No matter ; sample site, sample password

Hi @Ricardo_OJF

What PHP version is your site using currently?

Hi @Nick-B,

PHP version 8.1.9 just installed within last Local package.

Thank you,

Hi @Ricardo_OJF

This is interesting because PDO should be available with your version of Local and PHP.

Is this an older site you’ve had in Local or did you just recently build/import it?

Can you provide your Local Log? Retrieving Local’s Log File

Hello @Nick-B,

Local and plugin both “out of the box”.
Never used before.

Log provided in initial post.

Hi @Ricardo_OJF

This seems like a plug-in-specific issue since the error is originating from Independent Analytics itself.
One of our Local Devs checked the Query.php file, downloaded from the free plugin version, and it looks like the plugin tries to connect to the wp db directly via PHP’s PDO library using some custom connection logic. If it connected using WPDB calls instead that would allow it to work with more varied environments, including Local.

Similarly, with PhpMyAdmin - it’s as if the database isn’t being referred/pointed to correctly.
Are you able to use Adminer? Local handles the pointing in that instance so that may be telling if it works for you or not.

This is an old post but a good one on a user who details setting up PhpMyAdmin to work with Local - there is a lot of some config that has to be done, we don’t use PhpMyAdmin by default: How to add PHPMyAdmin to Local by Flywheel - The Inspired Developers

Hi @Nick-B

PhpMyAdmin : just can’t use adminer having PhpMyAdmin.
Problem solved as mentioned in your given link, and the same way to solve PDO connexion problem with Local (see below).

PDO connexion with Local : don’t think realy a plugin specific issue, since perfectly work in production (6000+ active installs, see map widget at : [https://observatoiredelajustice.org]).

@ben.turner reported a bug for this :
[Cannot import database through SSH - #5 by emsixteen]
No news about bug solving, but a tip : just manually add the port to ‘localhost’ in Local config file (thank you Ben).

other same solution :
[ManageWP's Local Sync throwing DB error on latest "Local" version]

solution : manually add the port to ‘localhost’ in config file (Local and/or PhpMyAdmin)

other topics with same issue :
[Warning: mysqli_real_connect(): (HY000/2002): No connection could be registered because the target computer specifically refused it. in C:\Users\Isabelle\Local Sites\monsitet\app\public\wp-includes\wp-db.php on line 1753]
[PDO Exception after migrating from Flywheel to Local]

=> both closed. no answear. no solution.

I suggest to add this solution to FAQ, waiting for Ben’s bug solving.

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.