Can't select database - Wordpress

浪子不回头ぞ 提交于 2019-11-30 22:00:34

For anyone who's still looking for solutions to this problem - please, check again your wp-config.php database credentials again. I had the same problem today and tried to over-complicate the matter by searching for advanced solutions, while I had a space in my DB_NAME field (was supposed to be 'wpdb' and was ' wpdb').

This space completely messed up my connection, I was even close to reinstalling the whole thing and losing all data.

If using LAMP -

Make sure that all privileges are granted for that database to the created mysql user. Under your MYSQL shell use the below

GRANT ALL PRIVILEGES ON database_name.* TO database_user@localhost IDENTIFIED BY 'user_password';

Where,

database_name = your database name as per wp-config.php

database_user = your user name as per wp-config.php

userpassword = your user password as per wp-config.php

By default

username : root

password : leave it blank

database host : localhost

table_prefix : wp_

It sounds like either you have not created a database or your wp-config file is not set up correctly. Have you edited wp-config.php file of wordpress and provided correct database name and user credentials. See Famous 5 minute installation of wordpress for details.

It took me way too long to discover that my msql databases were not working on any other websites either. I reinstalled Wamp Server and it worked.

Verify the wp-config.php file. I had the same error and the problem was related with the quotes: ‘root’ vs 'root'

edit: the correct one is single quote

'

For me, the solution was giving wp_user all permissions on the wp_db database.

I achieved this using the command line interpreter (CLI):

$ mysql -uroot -p
MariaDB [(none)]> GRANT ALL ON `wp_db`.* TO `wp_user`@`localhost` IDENTIFIED BY 'pass';
MariaDB [(none)]> exit;

After these operations, I restarted the database:

$ systemctl restart mysql

Of course, the database name (wp_db), username (wp_user), and password of the user (pass) can be different.

my problem was that when I granted permissions to the DB user the host did not match what was in the wp_config.php

/** MySQL hostname */
define('DB_HOST', 'localhost:3306');

I was granting rights with

GRANT ALL ON databaseName.* TO 'UserName'@'127.0.0.1';

This gave me access when I was connected to the local host through ssh but It did not match wp_config.php. so I had to Grant like this then it all worked.

GRANT ALL ON databaseName.* TO 'UserName'@'localhost';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!