WordPress Error establishing a database connection

2019-07-22 03:37发布

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,

    1. created new user with all privileges
    1. tired with root user.
    1. created and deleted the target database multiple times.

Nothing is working.

Does anyone know anything else I can try?

5条回答
走好不送
2楼-- · 2019-07-22 03:49

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.

查看更多
疯言疯语
3楼-- · 2019-07-22 03:52

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_Connection

Are 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

查看更多
祖国的老花朵
4楼-- · 2019-07-22 03:52

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.

查看更多
Explosion°爆炸
5楼-- · 2019-07-22 03:55

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 www.yoursite.com/admin and you should be able to log in.

查看更多
干净又极端
6楼-- · 2019-07-22 04:03

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:

sudo mkdir /var/mysql
sudo chmod 755 /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

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 to define('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!

查看更多
登录 后发表回答