Error establishing a database connection in my localhost - php

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:
DB_NAME: Your chosen db name (case sensitive)
DB_USERNAME: root
DB_PASSWORD: ""
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 !!

Related

Error establishing database connection in WordPress install

I am working with a managed server from 1&1 and I am trying to manually install WordPress with no luck. I went and downloaded the WP core files, uploaded them via FTP and then went into mySQL and created the database and username/password etc. and assigned the privileges. When I try to install wordpress via "www.example.com/wp-admin/install.php", I continuously receive the error:
Error establishing a database connection
I tried everything and triple checked my user,password, etc.
Here is my credentials (Password is hidden):
// ** MySQL settings ** //
/** The name of the database for WordPress */
define('DB_NAME', 'yourdb');
/** MySQL database username */
define('DB_USER', 'yourdb user');
/** MySQL database password */
define('DB_PASSWORD', 'yourpassword');
/** MySQL hostname */
define('DB_HOST', 'hostname');
Host name is always a localhost. for check your database credential is correct or not please feel a wrong value # let me know I am here
Try use 127.0.0.1 instead of localhost as the db host. Had the same issue and this fixed it for me.

Error establishing a database conection

While trying install wordpress i recieve following error
I use wampserver i have changed wp-config.php file and now it looks like this:
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'root');
/** MySQL hostname */
define('DB_HOST', 'localhost');//i used 127.0.0.1 too but no matter
define('WP_DEBUG', true);
wp-db.php file:
1379 line:
mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
1409 line:
$this->dbh = mysqli_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
but still no result I do not know what to do can anyone help me?
if you are using default configuration of xampp/wamp try with
define('DB_PASSWORD', ''); // for localhost
generally localhost db config:-
host = localhost
user = root
password = '' (blank)
Is root really the MySQL user you want to connect as? Is root its password?
It's usually not necessary and from a security standpoint potentially very dangerous to let web applications use your MySQL root user. Create a new user for your WordPress instance, give it its own database:
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO blog#localhost IDENTIFIED BY '3AmAbsKCsrKDw':
Then use that user
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'blog');
/** MySQL database password */
define('DB_PASSWORD', '3AmAbsKCsrKDw');
/** MySQL hostname */
define('DB_HOST', 'localhost');
define('WP_DEBUG', true);
That should let you connect. Verify that you can connect with those login credentials before continuing to your WordPress setup. WAMP includes a phpMyAdmin interface as far as I know, so try those credentials there.
Update your wp-config.php file like this
define your database name when you create on your localhost or server
define('DB_NAME', 'Your database name');
Ex:- You create your database name like "wordpress" then put database name like
define('DB_NAME', 'wordpress');
If you run your project in local always put root and when you upload database in your server you put your database user name when you create database
define('DB_USER', 'root');
Put your password when you create database on server other wise you can put ''
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('WP_DEBUG', true);

wordpress on xampp database error

Hi I am trying to install worpress on xampp to design and test my blog on but when I go to localhost/wordpress it keeps telling me that
"Error establishing a database connection"
Please help been trying everything.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
I am running it on Windows XP
Try create Wordpress database on your MySQL server
The error message would suggest that the details you have in your code sample are incorrect.
Do you have a 'wordpress' table?
Can you log into phpMyAdmin using the XAMPP suite using the account 'root' without a password?
You may need to setup a new user account with a password and grant the relevant privileges and then re-install Wordpress.

Error Establishing Database Connection hell continues

I have created a copy of may wordpress site locally (importing the SQL) and going through one connection bug after the other for days and I'm really almost giving up.
I went through several Database connection errors and now I am on another for which I cannot find an answer in the forums.
I am running the website locally after downloading it and importing the dabase so I have:
define('DB_NAME', 'db_mysitename');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'root');
/** MySQL hostname */
define('DB_HOST', 'local.mysitename');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/** debuging mode*/
define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );
But when I navigate to local.mysistename/ I get the following:
Warning: mysql_connect(): Unknown MySQL server host 'http' (2) in /Users/me/Sites/mysitename/wp-includes/wp-db.php on line 1141
So I added a database test script in db-test.php
And illogically this works:
wp_commentmeta wp_comments wp_links wp_options wp_postmeta wp_posts wp_term_relationships wp_term_taxonomy wp_terms wp_usermeta wp_users
Why would it work for the test script but not for the website? Any ideas?
Please help.
just put all above information in wp-config.php file at root directory of your wordpress blog
and please change define('DB_HOST', 'local.mysitename') to define('DB_HOST', 'localhost')
it will work
local.mysitename looks like an alias you would have listed in your hosts file, which means an alias for a location that you access over http. You don't generally access databases over http connections, so that looks like it could be the problem. If the database is running on your computer, then you'll want to use localhost or whatever your machine's local IP is.

Installing wordpress on OS X error establishing connection

I am really confused by the wordpress installation. The wp_config file has the root username and password for my instance of mysql (localhost) and I have created a blank database called 'wordpress' (I am not sure whether I am supposed to have a database created to begin with).
When I go to http://localhost/wordpress/ I get an 'Error establishing a database connection' message. Am I suppose to have a database called 'wordpress' to begin with?
These are my credentials from the config file:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'friday');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
See http://techtrouts.com/mac-mysql-does-not-connect-on-localhost-but-connects-on-127001/
for some information on this.
Basically, on a default installation on a Mac you have to connect to 127.0.0.1 instead of localhost. So if you change the following it should work.
/** MySQL hostname */
define('DB_HOST', '127.0.0.1');
With Wordpress you should have a database setup already (no tables, just the database).
So the first option should be the database name. If you're on shared hosting there might be a prefix before the database name.
Then the user of the database (which should be set up when setting up the database).
Then the password of that user.
Then, finally, the host is usually localhost, but if you're on shared hosting it could be different. You'd have to check your hosting providers docs to be sure.
Also, the first place you should go to is: http://localhost/wordpress/wp-admin/install.php

Categories