WP-CLI Cannot Connect to Database due to Vagrant

Since the issue is probably DB configuration you could try adjusting it conditionally in wp-config.php:

if ( defined( 'WP_CLI' ) ) {
    define( 'DB_HOST', 'example.com' );
}
else {
    define( 'DB_HOST', 'localhost' );
}

Leave a Comment