Error Establishing a Database Connection
I am adding two new websites to my linode . It was installed using the prebuilt wordpress stack script so I was never sure what the user name for the mysql was. I am trying to import the database using
mysql -u username -ppassword database_name < FILE.sql
but I am getting permission problems. I have tried the command to list mysql database users but I also get an error about permission for that. What should I do here?
bellajo.com is the site / database I am trying to link.
PS :: After doing this and getting to this part, my website that was previously up is now having a database issue!! I did not even touch anything regarding that website ! Can anyone shed some light on this I am at a loss of ideas.
19 Replies
If you can log in as root, check the permissions for the user and db that you're trying to use to import your sql file.
The output came out with this
+------------------+
| user |
+------------------+
| root |
| root |
| |
| root |
| |
| debian-sys-maint |
| root |
| wordpress |
+------------------+
I got the line of code to transfer the sql file into mysql database to work but it does not seem to be connecting. Still having the error establishing a database connection.
When this line executed properly for bellajo.com is when the site (bwsurfshop.com) that was already running became effected.
I guess the first question is how to get my original sites database linked back up. Then move to figuring out the other sites. Any thoughts on how I would accomplish this?
-Tantrik
Am I correct in assuming that you're using the 'wordpress' user in your db configuration settings? What do you get when you run this command in mysql:
show grants for 'wordpress'@'%' ;
MSJ
I ran that line and came out with this,
ERROR 1141 (42000): There is no such grant defined for user 'wordpress' on host '%'
Which I would assume means there is no permissions set to any users? Appreciate your time and help MSJ !
EDIT :: I am not a fan of having multiple users since I am the only person using the server. Would if be possible to simple have one master user that can control all the databases?
-Tantrik
I was guessing that your database user for your site was 'wordpress'. It's never a good idea to have your website or web application use the root user for database access. It's is a very bad security practice.
What user is defined in your wp-config.php file? It looks something like this:
/** MySQL database username */
define('DB_USER', 'your db user name');
MSJ
// ** 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', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', ‘passwordhere’);
/** MySQL hostname */
define('DB_HOST', 'localhost');
Check all the settings on the SQL side and seems to be good. Any ideas from here?
-Tantrik
You need to give the 'wordpress' mysql user the correct permissions to access the 'wordpress' database or use a different mysql user to connect to the database.
@Main Street James:
You are using the 'wordpress' mysql user but have not given it any privileges (based on your previous posts). That is why it can't access the database.
You need to give the 'wordpress' mysql user the correct permissions to access the 'wordpress' database or use a different mysql user to connect to the database.
How would one achieve this?
@Tantrik:
How would one achieve this? Running this command in mysql will do it:
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
"wordpress.*" refers to the database and "'wordpress'@'localhost'" refers to the user.
-Tantrik
It still may say '0' rows affected. You should try to see if Wordpress connects.
EDIT :: I never made a SQL backup for my main website although all the actual web files are unaltered from the working config. Did not expect this site to go down and have DB issues while working on a completely different site
EDIT EDIT :: Just found out there is a way to dump the database info into a sql file which I can maybe use to connect the site back up? Is this possible? I am having trouble using the command
mysqldump -u [username] -p[password] [databasename] > [filename.sql]
- it seems to go through without any output but I have no idea where that sql file would be if it was even created. Thanks again !
-Tantrik
"We were able to connect to the database server (which means your username and password is okay) but not able to select the [databasename] database."
If I manually put the info into a wp-config.php file, I get your "Error establishing a database connection" error.
I've double checked for typos, I've tried localhost
, 127.0.0.1
, linode_IP
with no luck (also changing the host in mysql permissions).
I can access the database using the command line mysql -u my_user -h 127.0.0.1 -p
and use database my_database;
.
Any suggestions?
EDIT :: Just checked and make sure the 'wordpress' DB has information in it and it seems to all be there, Just not sure how it got disconnected from my site in the first place. The answer must be so trivial.
EDIT EDIT :: Still plugging away at this for the 3rd day straight .. all of my sites are getting this SAME error. The answer has to be the same throughout all the sites, seems like theres a problem with sql talking to the wordpress config files. Been scouring the web but nothing it turning up. Will post back if I find any other ideas.
-Tantrik
-Tantrik
If your other domain resolves and access the database then it is not the server and rebuilding will only be for practice.
You may want to scuttle this wordpress install and try again.
MSJ
try this
this is correct :
CREATE DATABASE wordpress;
CREATE USER wpuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost;
FLUSH PRIVILEGES;
add @localhost after username database and remove letter ' .