db_password db_user db_host db_port db_name – Code Example


In this article we will discuss about wordpress configuration to connect website with database like mysql. We will check out db_user, db_host, db_port, db_name and db_password fields.

WordPress has a configuration file known as wp-config.php.

Code Example

The wordpress config file contains information regarding database connection parameters like db_name, db_user, db_password etc. It also has some keys defined for securing authentication and sessions.

 * The base configuration for WordPress
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 * This file contains the following configurations:
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * @link https://wordpress.org/support/article/editing-wp-config-php/
 * @package WordPress

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name' );

/** Database username */
define( 'DB_USER', 'database_user_name' );

/** Database password */
define( 'DB_PASSWORD', 'database_user_password' );

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

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

 * Authentication unique keys and salts.
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 * @since 2.6.0
define( 'AUTH_KEY',         'some_auth_key' );
define( 'SECURE_AUTH_KEY',  'secure_auth_key' );
define( 'LOGGED_IN_KEY',    '#*ESK' );
define( 'NONCE_KEY',        '$*HKJJHSK' );
define( 'AUTH_SALT',        'JS$*HUGHJKS' );
define( 'SECURE_AUTH_SALT', '$*(*T&WGJF' );
define( 'LOGGED_IN_SALT',   '(^&#JFJK' );
define( 'NONCE_SALT',       '(**R#*KFS' );


 * WordPress database table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

 * For developers: WordPress debugging mode.
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 * @link https://wordpress.org/support/article/debugging-in-wordpress/
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

The definitions of parameters are –

Setting Parameters Values & Description
DB_NAME Name of website database in mysql
DB_USER Connected user account for the database
DB_PASSWORD Password of user account
DB_HOST Localhost or ip of server where mysql running
DB_CHARSET Default character set for db like UTF8

There are two kinds of passwords – root_password and db_password.

Root password is for the root or admin account which is used for operations like CREATE, DELETE, ALTER etc. These operations could be destructive and hence permissions should be given with care. That’s why root_password is used. This account can access all the databases on the server. It is not used in applications.

db_password, on the other hand, is used for accessing a single database. We can keep it restrictive so that no destructive permissions like DROP would be granted. This db_password is used in applications like WordPress websites for db communication.