Title: Error establishing a database connection using wp-cli
Last modified: January 19, 2022

---

# Error establishing a database connection using wp-cli

 *  [grifgr10](https://wordpress.org/support/users/grifgr10/)
 * (@grifgr10)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-using-wp-cli/)
 * I have a container deployed in an Azure App Service that has WP-CLI also installed.
   My wp-config.php gets the database info using the getenv_docker environment variables.
   And therefore WP CLI fails to establish a connection to the mysql database also
   running in Azure.
 * I have spent 2 days searching and obviously am not searching for the right info
   as I can not find a solution to allow wp-cli to be able to read the wp-config.
   php correctly or find another way to pass the database info to wp-cli to know
   where the database exists.
 * Can someone please help point me into the right direction?
 * My wp-config.php looks like this for the DB info.
    ==========================
   ======================================================== /** MySQL hostname */
   define( ‘DB_HOST’, getenv_docker(‘WORDPRESS_DB_HOST’, ‘mysql’) ); /** The name
   of the database for WordPress */ define( ‘DB_NAME’, getenv_docker(‘WORDPRESS_DB_NAME’,‘
   wordpress’) );
 *     ```
       /** MySQL database username */
       define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username') );
       /** MySQL database password */
       define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password') );
       ==================================================================================
   
       Additional note... it appears since getenv_docker is not working it is trying to use default info...   Of course that will not work. :(
       ```
   
 * # wp config list –allow-root
    +———————+——————————————+———-+ | name | value | 
   type | +———————+——————————————+———-+ | table_prefix | bv_ | variable | | configExtra
   | | variable | | DB_NAME | wordpress | constant | | MYSQL_CLIENT_FLAGS | 2048
   | constant | | DB_USER | example username | constant | | DB_PASSWORD | example
   password | constant | | DB_HOST | mysql | constant | | DB_CHARSET | utf8 | constant
   |`
    -  This topic was modified 4 years, 4 months ago by [grifgr10](https://wordpress.org/support/users/grifgr10/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-using-wp-cli/#post-15270613)
 * > My wp-config.php gets the database info using the getenv_docker environment
   variables
 * Have you deifned the same set of env variables in your yml file in both the WordPress
   container and the CLI container? They need to match.
    Make sure you provide a
   password for root – we can’t use root no password anymore. 🙁
 * Btw, are you tied in to use Docker?
    I drank the koolaid a few years ago, and
   finally bailed on it. Was too much of a barrier / time sucker most of the time.
   Back to good ol’ reliable VM.
 *  Thread Starter [grifgr10](https://wordpress.org/support/users/grifgr10/)
 * (@grifgr10)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-using-wp-cli/#post-15272493)
 * I have wp-cli setup in the same container as WP is running. If I change the wp-
   config.php to have the values for the database connection everything works fine.
   But if the wp-config.php has the getenv_docker function to pull the values wp-
   cli fails to connect to the database. But the WP site works just fine.
 * As a note on docker, we were pushed to begin using it for this project and had
   a consultant come in and help us build this out. I do not see any specific yml
   files for the environment other than the pipeline yml. I am having issues using
   what they setup as it writes an docker image out there but then changing info
   that is dependent on environment is a challenge. Meaning dev, qa and prod have
   some different params needed…
 * Grant

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Error establishing a database connection using wp-cli’ is closed to new
replies.

## Tags

 * [cli](https://wordpress.org/support/topic-tag/cli/)
 * [wp-cli](https://wordpress.org/support/topic-tag/wp-cli/)
 * [wpcli](https://wordpress.org/support/topic-tag/wpcli/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [grifgr10](https://wordpress.org/support/users/grifgr10/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/error-establishing-a-database-connection-using-wp-cli/#post-15272493)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
