I am new to WordPress, and I am trying to setup it at my local machine.
I am getting error like “Error establishing a database connection”.
I tried all solutions from WP blogs,
-
- created new user with all privileges
-
- tired with root user.
-
- created and deleted the target database multiple times.
Nothing is working.
Does anyone know anything else I can try?
Error establishing a database connection
doesn’t get any simpler than that. Your password, database name, user name, or host is wrong. See http://codex.wordpress.org/Common_WordPress_Errors#Error_Establishing_Database_ConnectionAre you sure about using
localhost
as the server? Are you using MAMP or WAMP?Try using Adminer http://www.adminer.org/ on your PC/Mac to find the database name, etc., and to admin the database when needed.
If you know can use a shell, try logging into the MySQL server and trying
mysql> show databases;
to list all databases to check your database name.
And try
mysql> mysqlserverinfo --server=root:pass@localhost -d --format=vertical
to get port info, etc. See http://dev.mysql.com/doc/mysql-utilities/1.6/en/mysqlserverinfo.html
I used MAMP for the MySQL server, and used its phpMyAdmin interface to create the database for WordPress and specify its user and password.
Host, for the new database, was “%” on the “User” tab of phpMyAdmin, which it said was supposed to allow any value, and did let me get a certain way through the process. But, I ended up going into “Login Information” under the “User” tab in phpMyAdmin, and changing “%” to “localhost”.
That allowed me to finish setting up WordPress.
For future readers, if you are on OSX Yosemite (possibly other versions of OSX as well) and get “Error establishing a database connection” with a local WordPress installation, you may need to do the following:
Yosemite looks in the wrong location for the mysql.sock file, so creating this symlink to the correct location solves the problem.
The reason the missing symlink is a problem for WordPress specifically is because in your wp-config.php file,
define('DB_HOST', 'localhost');
will not work. An alternative workaround is to change this value in your wp-config file todefine('DB_HOST', '127.0.0.1');
.The OP didn’t say what details they changed in their wp-config file to solve the problem (perhaps it was this DB_HOST parameter) so I just thought I’d post this since I wasted a lot of time trying to figure it out!
I tried all these suggestions and still couldn’t get it to work. However, I had installed MySQL v8.0.12 and noticed that in the ‘Users and Privileges’ section, under the user I had set up, the ‘Authentication Type’ for the password was set to some kind of ‘sha2’ setting.
After trying 100 different things, I eventually fixed this by uninstalling then re-installing MySQL, and during the re-installation, specifically choosing the option button that refers to maintaining compatibility with previous versions of MySQL.
I think this resulted in my passwords not being automatically hashed, which enabled WordPress to successfully connect to my MySQL database.
What worked for me:
-I moved the wp-config.php file into another folder
-Refreshed the browser and WordPress will try to re-install
-choose a language
-A message should say WordPress is already installed and will take you to the database setup page.
-Enter the same db name, username, password, and host (usually localhost).
-Got to http://www.yoursite.com/admin and you should be able to log in.
I had this issue and I have searched a lot but no one mentioned a fix like mine!
I checked my disk size and I found that my disk size was 100% used. I tried to clean up some of the files but still there were very large files taking up a lot of space. I kept looking and found that the mysql ./data folder occupied 90% of my disk space. It was the binlog files! Very large files I ended up cleaning them up using the Reset Master method. There is another method PURGE BINARY LOGS which didn’t work for me. I had to use Reset Master. Just follow the steps and make sure you have a good backup. Good Luck.
Try this before anything! It fixed my issue.
sudo service mysql restart