Error establishing a database connection on wordpress - php

i have a blog with wordpress but sometimes i have problem with that
i got blow error
Error establishing a 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 %s. This could mean your host's database server is down.
Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums
and this is my config file
define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');
/** MySQL database username */
define('DB_USER', 'dbusername');
/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');
/** MySQL hostname */
define('DB_HOST', 'mysite.com');
why i got this error sometimes what do you think about this problem?
i contact with my admins server and they said "we dont have any problem with server and mysql service"
does my server have problem or my config have problem?

If your are not using default port 3306 for MySql, do give the host name with port number.
define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');
/** MySQL database username */
define('DB_USER', 'dbusername');
/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');
/** MySQL hostname */
define('DB_HOST', 'localhost:3307'); //If you are not using default port number, do give post number along with localhost.
This would work

why i got this error sometimes what do you think about this problem?
That's the key; if it only happens sometimes, it's an intermittent issue at the webhost. The webhost needs to look in the MySQL logs and PHP logs for connection errors, timeouts, MySQL crashes, etc, anything that will point to the cause of the intermittent issues.
If you had "Error establishing a database connection" all the time, that points to a definite error you made in wp-config.php.
Tell the webhost and administrator to look at their logs to see when the MySQL server is going down and why.
If this is your own server, you need to know the OS and other details so you can search Stack Overflow for the information. Log locations vary, depending on the OS.

If you get it 'sometimes' then it means the PHP Scrpt wasn't able to connect to the database. One of the various reasons could be database server down for a while.

first type mysql -u root -p and enter the your mysql password
then type GRANT ALL PRIVILEGES ON mydbname.* TO dbusername#localhost;
then FLUSH PRIVILEGES;
and finally exit

Try changing your DB_HOST to localhost
** MySQL hostname */
define('DB_HOST', 'localhost');
Furthermore, have you set up the database and filled in the username, password & database in your config?

First thing you should do is to make sure that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.
You can do this by adding the following line in your wp-config.php file:
define('WP_ALLOW_REPAIR', true);
http://cdn4.wpbeginner.com/wp2-9/dbrepair.gif
Remember, the user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.
Regard
LatestTutorial.com

get the correct DB host name from the database
use following quesry for mysql
select ##hostname;
change the value of the DB_HOST to output of above query

Some time this happen , just because of incorrect credentials so check your credentials or try to reset your user name and passward , some time host issue or you can repair the database just go to your wp-config file and write
define ( 'WP_ALLOW_REPAIR' , true);
and repair it and don't forget to remove this line after repair.

There are many reason for the issue if you get the error only sometimes
If your database is very big, it can not handle the queries. ( You probably see 'too many database connections' or 'user already has more than 'max_user_connections' active connections' errors on error logs. So try to reduce database tables size.
If you got the error on both backend and frontend, check your database credentials are correct.
If the error only on the front end. try to repair database by adding the following line of code in wp-config.php
define('WP_ALLOW_REPAIR', true);
Then go to 'http://www.yoursite.com/wp-admin/maint/repair.php' and click 'repair and optimize database' button.

Related

What we need to put in wp_config.php?

I tried uploading a wordpress site and I arrived to the step when I need to modify wp-config.php
Here's the code.
define('DB_NAME', 'replace_with_database_name_you_noted_down');
/** MySQL database username */
define('DB_USER', 'replace_with_new_host_mysql_user_name');
/** MySQL database password */
define('DB_PASSWORD', 'replace_with_new_host_mysql_password');
/** MySQL hostname */
define('DB_HOST', 'replace_with_new_mysql_host'
I don't understand what means "replace with new mysql host", because I have the files in wordpress directory and when I try to access the page, it returns "403 forbidden.The access for the server was
denied".
I mention that i tried that on a simple installation wordpress site, I cannot upload my site on cpanel, can you send me a tutorial and give me some suggestions please ?
In order to work wordpress need a sql database. You need to create one and a user with a password.
If you have cpanel you can install directly wordpress with one click with softaculous or other. This will create a database automaticaly and fill the wp-config for you.
If you install wordpress "manually", you have to fill the wp-config yourself. For MySQL hostname, you can try localhost (if the sql database and ftp hosting is at the same place)

Valet not working for WordPress site: Error establishing a database connection

I am having a problem connecting to my WordPress site using Valet. I get the following error:
Warning: mysqli_real_connect(): (HY000/1045): Access denied for user
'db_username'#'localhost' (using password: YES) in
/Users/.../Documents/WordPress/.../wp-includes/wp-db.php
on line 1531
Error establishing a 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.
Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you’re unsure what these terms mean you
should probably contact your host. If you still need help you can
always visit the WordPress Support Forums.
This is odd, as I am able to connect the page that is online to this database. This makes me believe that all of the following settings should be correct:
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST
DB_CHARSET
DB_COLLATE
I also wanted to note that I do not have any redirection issues. I had this at first and solved it by changing the "DOMAIN_CURRENT_SITE" to my Valet domain.
Example:
define('DOMAIN_CURRENT_SITE', 'valetdomain.test');
I am also able to connect to the database within Sequel Pro on my computer with the same login information.
Note: I can use Valet on my other pages locally as well and that works fine.
So, I have Valet working, Sequel should be working, and the site works online. I just can't seem to get them all working together :(
Is it possible that the wp-config settings or some other settings must be different when connecting a WordPress site locally, via Valet in my case, as opposed to online?
Things I have tried:
Creating a new user within cPanel, adding them to this database, and updating wp-config accordingly
using no password and connecting via Root
using my server's IP address as the hostname instead of localhost
using 127.0.0.1 as the hostname instead of localhost
changing the siteurl and home within wp_options table to the .test domain that I'm using with Valet (this just kills my online site, but doesn't help me connect the DB for the local site in Valet)
One thing I'd like to note here is that if I use...
define('DB_USER', 'root');
define('DB_PASSWORD', '');
... then the error changes from the one above to simply "Error establishing a database connection." Is this somehow a "better" error, meaning that I could be closer to solving this problem?
Final note, I am using WP Multisite. Not sure if this makes any difference.
I was able to solve the problem by closing everything and restarting WordPress from scratch. I think the problem was that I had two versions of SQL running on my computer, one from Brew and the other from the Mac. This may have caused the problem. I'm not sure if this is the best advice, but it is what helped me.

Error establishing a database connection with WordPress and Azure

I have hosted a WordPress site, http://edufunweb.azurewebsites.net/, on Azure. It was working fine until I wanted to host another site. So I went to the edufun wp-config.php file in Microsoft Webmatrix and changed the line
$table_prefix = 'wp_';
to
$table_prefix = 'wp_2';
(or maybe it was the other way around) in order to have different tables in the database for each of the sites. Then I deleted the other site and now with whichever codes above I get a
Warning: mysql_connect(): Access denied for user 'abcd'#'xxx.yyy.zzz.xx' (using password: YES) in D:\home\site\wwwroot\wp-includes\wp-db.php on line 1461
Error establishing a 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 eu-cdbr-azure-north-c.cloudapp.net. This could mean your host's database server is down.
Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.
Moreover, if I connect to http://edufunweb.azurewebsites.net/wp-admin/
I still get the same error.
Your help is highly appreciated as I need my website back on track!
I don't think this is a WP multi-site issue. This typically is caused when the connection string to the host mysql server is not correct.
Here's an easy way to test this.
Open wp-config.php and locate the following lines.
/** MySQL database username */
define('DB_USER', 'user_name');
/** MySQL database password */
define('DB_PASSWORD', 'user_password');
/** MySQL hostname */
define('DB_HOST', 'some_hostname');
Next, open your WP site in the Azure Management Portal. Go to the Configure tab and scroll down to Connection Strings. Click "Show Connection Strings". Copy it into a text editor and compare the values to what you see in wp-config.php. If those values are not the same then keep both copies and do the next step.
Next, open your local shell and open mysqladmin by typing in the following, replacing the values from above here below (without single quotes), note there is no space between the -p parameter and the password value itself.
mysqladmin -u user_name -puser_password -h some_hostname
One of those connection values should be correct and if so replace the one that is not correct with the one that is. If neither work, then go back to the Azure Management Portal to your site, click on Linked Resources, click the item that appears and you should be in the Clear DB management portal where you can get the correct connection information for your MySQL Database.
After you have sorted you can go configure your WP Multi-site. Here is an article on how to do that for Azure Web Apps, http://azure.microsoft.com/en-us/documentation/articles/web-sites-php-convert-wordpress-multisite/
hope that helps.
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', '');
define('PATH_CURRENT_SITE', '');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
those lines add to config.php and check wp-admin, there is an option network admin. Go to the network admin and after that go to the settings and setup network from Network Setup option.
Go to the Site option and Add New Site.

EasyPHP - Taking WordPress live to localhost

I have been giving a task for a client to take their existing word press database and make changes to the client specifications. However I do not want to edit this database on their live website so I am trying to pull it from their server and work on it locally.
The problem I am having is that I managed to drag all the files successfully from their host and put them onto my localhost, however when I try to view it locally I get the error: "Error establishing a database connection"
As they can't give me their database to work locally on, I am in the position where I have their files locally on my machine but I am trying to access their live database.
So when I pulled the files down locally, I expected that my local machine will just connect to their live database automatically.
In the wp-config.php file I have the settings:
define('DB_NAME', '');
/** MySQL database username */
define('DB_USER', '');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
Removed the db_name, username and password
The line I am looking at is 'localhost', would this need to be changed to their host? Because from what this says is that it will check the localhost on my local machine for the database which I do not have.
However on the server it would say check the localhost on the server which would be there?
So to sum this up, to get this working correctly, would I either need:
The database to export to my local machine
The IP / Hostname of where the database is stored?
Also is it possible to find out what this is without directly contacting the client as I doubt they will know this.
Cheers
I managed to get the IP they were using by pinging the live website through the command line.

Wordpress installation error: 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?
You're trying to use wordpress locally i assume. 127.0.0.1. Then you must have a local database to store wordpress's data. something like WAMP on windows or LAMP on linux. If you already have one of these then you are probably getting an error because your database is not turned on. or you have not edited the wp-config file to include the database the username and password for the database you created. beyond that wordpress does the rest of the work.
You are not very clear of what system you are using, more info would be needed to diagnose your error completely.
so what OS?
what web server are you using? (apache WAMP or LAMP?)
is your database on?
have you edited the wp-config file to include your db info?
The error is pretty straightforward, but could come from a number of different sources.
What that error message means is that you have your setup file misconfigured. WordPress requires a SQL database it can create tables, read, write, and otherwise modify to make and store its content. The configuration you have set in your wp-config.php file is wrong.
Steps to Fix This
Make sure you have an SQL database
Make sure you have a user in your SQL server that can access that database fully and can log in from outside sources
Make sure you know the host, username (for the user previously mentioned), that user's password, and the database name
This is where you enter these into wp-config.php. By default, WordPress only comes with wp-config-example.php so you must set this information in that file, then rename it wp-config.php before navigating to your setup screen.
Also Note: It's possible WordPress cannot access your database because the user you are trying to log in with does not have outside access permissions. Might be worth checking. Also, the host is not always straightforward; if you use Dreamhost or Amazon Web Services, you cannot normally specify localhost as the location of your database server, unless you specifically set your machines to be that way.
WordPress can't...well... "establish a database connection", enable debugging in wp-config.php, this will show more information about the error, it could be a wrong password or server not responding...
Add this line anywhere in the file (like this ).
define('WP_DEBUG', true);
If the line is already there make sure it's true and not false.
answer is :
define('DB_PASSWORD', '');

Categories