• Hi, I am installing wordpress on docker. I am stuck in the last step. while my mysql server is running and username and password is ok I get this error. Mydatabase server is localhost. Can anyone help me please?

    Error establishing a database connection

    This either means that the username and password information in your wp-config.php file is incorrect or that contact with the database server at localhost could not be established. This could mean your host’s database server is down.

    • Are you sure you have the correct username and password?
    • Are you sure you have typed the correct hostname?
    • Are you sure the database server is running?

    If you are unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress support forums.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please try changing the database hostname from localhost to 127.0.0.1and check if it resolves the issue.

    @thvlo

    When running WordPress in a Docker container, and MySQL in another Docker container, you cannot connect to MySQL using “localhost” as the hostname because each Docker container is isolated and has its own “localhost”. You should use the name of the Docker container running MySQL as the hostname.

    To find out the name of your MySQL Docker container, you can run the following command:

    docker ps

    This command will display a list of running Docker containers and their names. Look for the MySQL container and note down its name.

    Then, in your wp-config.php file, you should replace “localhost” with the name of the MySQL Docker container.

    In case you are using docker-compose to manage your containers, you should use the service name defined in your docker-compose.yml file as the database host.

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

The topic ‘Error establishing a database connection’ is closed to new replies.