Site shell wp db cli connecting to wrong port

What issue or error are you experiencing?

wp db cli in the public folder doesn’t work without editing WP-config
Other wp db have similar problems but that doesn’t really matter for the problem itself.

If this is the expected behaviour, then of course this whole post can be dismissed.
Could also be I missed some mandatory setup or it’s because of my environment, if so, apologies.


What steps can be taken to replicate the issue?

  • Create new site (called site in this example)
  • PHP version 8.2.23/Nginx 1.26.1/MySQL 8.0.35 (The basic setup)
  • Open Site shell
  • Navigate to the /public/ folder
  • Run wp db cli
F:\dev\site\app\public>wp db cli
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

If I edit the DB_HOST in public/wp-config.php to use the port that’s shown in the database tab

/** Database hostname */
define( 'DB_HOST', 'localhost:10005' );

the wp db cli works fine.

Site (as well as admin) and Adminer both work fine without this change. It’s just the wp-cli that has issues.


System Details

  • Local Version:
    Tested both 9.2.2+6771 and 9.2.2-b6769
  • Operating System (OS) and OS version:
    Windows 11 Pro 24H2 (26100.3194)

Local Logs

I didn’t see anything relevant in the logs but here.
local-logs.zip (5.2 KB)

Thank you for spinning up this bug @jimihenrik! It looks like we’ve had some similar reports of this before and the Local team is taking a deeper look.

1 Like