error in establishing database connection in wordpress

I am facing error in establishing database connection in wordpress my login credentials are right but it stills shows error it shows error like “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” however my wp-config-php is still not created how can this be solved

my wp-cofig-php is still not created but it shows me error in this so how can this be solved

  • Provide correct user name / password combination and make sure local mysql is running.

    – 

  • wp-cofig-php is still not created” – that seems like your problem then? How is WP going to know what u/p to use if you haven’t configured it?

    – 

  • It sounds to me like you are about two minutes into what WordPress calls its famous five-minute installation. It might be wise to start over.

    – 

Yes, this sounds like you’ve still got a little work to do:

PRE-5-MIN-INSTALL (okay to do during)
A. Make sure you have MySQL or Mariadb installed, and that you have a username, password, and database name. I usually test the build by logging in directly (mysql -u my_username -p).

DURING 5-MIN INSTALL
B. Copy the wp-config-sample.php file and edit it.

.

Here’s how I might do it on Ubuntu:

A. Note, if you’re not using Linux, here’s directions for other operating systems: https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/

You can install the MySQL server with the following command. During the installation process, you’ll be prompted to set a root password for MySQL.

sudo apt install mysql-server

After installation, you can run a security script to secure your MySQL installation:

sudo mysql_secure_installation

next I usually run sudo mysql -u root to log in
then alter user 'root'@'localhost' identified by 'pass321'
to set the root password to pass321

I personally create a new username, password, and database for wordpress. You can do that like so:

  • Log in to your MySQL/MariaDB server as the root user:

    mysql -u root -p
    
  • Create a new database for WordPress. Replace your_db_name with your preferred database name:

    CREATE DATABASE your_db_name;
    
  • Create a new user for WordPress. Replace your_user and your_password with your preferred username and password:

    CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'your_password';
    
  • Grant the user privileges to the database:

    GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_user'@'localhost';
    
  • Flush the privileges to apply the changes:

    FLUSH PRIVILEGES;
    
  • Exit the MySQL/MariaDB shell:

    EXIT;
    

B. Next you’ll be using this username, password, and database_name in the wp-config.php file you make!

Navigate to where your wp-config-sample.php file is and type this:

cp ./wp-config-sample.php wp-config.php

This will copy the file into the same directory with the name wp-config.php

Next edit the file

sudo apt install nano
nano wp-config.php

scroll down to where you find lines like this:

define('DB_NAME', 'your_db_name');
define('DB_USER', 'your_user');
define('DB_PASSWORD', 'your_password');

and put in your new values!

After you save the file, wordpress shouldn’t complain about talking to your database anymore 🙂

Leave a Comment