简体   繁体   中英

Error establishing a database connection in my localhost

I am trying to install Wordpress in my localhost Xampp server

But every time I got an error message with

error establishing database connection.

This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at localhost. This could mean your host's database server is down.

I have already googling but not get the correct answer yet.

I add define( 'WP_ALLOW_REPAIR', true ); in wp-config.php but not solved.......

This means wordpress can't find your database.

Navigate to http://localhost/phpmyadmin . Where it says create new database, choose a name for your database.

Next, open up wp-config.php in the root of your wordpress folder, and update the four values shown below to reflect your new database.

The default credentials for your newly created database are:

  1. DB_NAME: Your chosen db name (case sensitive)
  2. DB_USERNAME: root
  3. DB_PASSWORD: ""
  4. DB_HOST: localhost
/** The name of the database for WordPress */
define('DB_NAME', 'case sensitive chosen db name');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', '');

/** MySQL hostname */
define('DB_HOST', 'localhost');

I have solved my error as below procedure.

While installing Wordpress in localhost, first set some credentials of the file wp-config-sample.php as below

/** The name of the database for WordPress */
define( 'DB_NAME', 'learn_wordpress' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', '' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

and save the file name as wp-config.php and run again localhost/wordpress in the url.

It's done !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM