Hello, I got the following error when installing Drupal 7 on 1&1 (1and1) shared hosting.

Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2).

The solution was to go to Advanced Options - Database host on the Drupal "Set up database" page.

Replace localhost with the host name provided by 1&1 in Control Panel > Database Settings.

I thought I would document it in case this is useful for someone else out there.

Comments

johnlaine’s picture

Had the same error message on Godaddy and this was the fix.
Just to clarify for others:
In your settings.php file change the database setting 'host' from 'local' to whatever your hosting provider calls it.
Thanks again!

aadmi’s picture

I had the same error. By adding 'host' as provided by godaddy in Hosting Control Center for the database from 'local' resolved the problem.

Thank you.

enidsera’s picture

thanks for the fix

haebooty’s picture

I had this same error and a hell of time reinstalling my site after transfering hosts so gave up and tried just a new install and received this error.

Changing in advanced options for the host to "WEBSITENAME.ipagemysql.com", as indicated under their sql page solved this.

siteorganizer’s picture

#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)
What do you mean by Advanced Options?

ZeJimmeh’s picture

Thank You!

Worked for me!

korte40’s picture

If you get this error during installation using a GoDaddy hosting account you'll need to go to the 'advanced settings' at the bottom of the Drupal installation page and:

> paste the MySQL server name you get from your GoDaddy account (for example it'll look like this: data1db.db.4496066.hostedresource.com).

> Overall, everything about the Drupal install is very logical. There are no hidden meanings to what Drupal is asking except for this part if you have GoDaddy hosting account. (Linux hosting that is).

Hagar72’s picture

I've changed the database host from "localhost" to "127.0.0.1" and it works fine for me

fikifir’s picture

After install uninstalling for about 5 times, finally.
thanks.

Jemik’s picture

Thank You!

1q84’s picture

Fixing this was my very first Drupal breakthrough, Thanks michaellenahan!

fraxinus’s picture

@Korte40
This error message had stumped me for ages when trying to install D7 on shared hosting. Delighted to report that your advice worked for me.

p_rooster’s picture

Yes by scrolling down to the Advanced Options I was able to put in the actual hostname of the server (DNS Name) and away it went!

Alfgabo’s picture

When installing on Network Solutions shared hosting it worked for me also, using the server's ip, instead of "localhost"
Thank you

rafael1diaz’s picture

Hmmm I'm installing Drupal 7.2.2 (Network Solutions) and at the database setup screen the only thing I see under advanced options is:
Database file *
The default entry is: sites/default/files/.ht.sqlite

the text underneath is:"The absolute path to the file where Drupal data will be stored. This must be writable by the web server and should exist outside of the web root."

I don't have an option to change the database hostname or server address.

Am I missing something?

Chinelo’s picture

Thanks for this saved me alot of time !!!! Problem solved !!

dbusarow’s picture

This works for dotCloud too.
Whoda thunk that localhost wouldn't work.

Thanks!
Dan

thelustginslanger’s picture

Worked for me as well. Thank you!

markosaurus’s picture

It's probably because the hosting provider doesn't have an alias in place from 127.0.0.1 to localhost. (It's an industry standard address, so not sure why they wouldn't?)

So if you replace "localhost" with "127.0.0.1" you're essentially just taking out the reliance on the missing alias, hence fixing the issue.

smallcoder’s picture

Had this problem with a new VPS server and this solved it straight away. Many thanks - lifesaver !

markosaurus’s picture

If it's a VPS then you can probably fix this by looking into your DNS if you have time.

viola_chisto’s picture

I did it and it's works perfectly. Thanks

DynV’s picture

Thanks a lot! On byethost (from BYET Internet Services), one can see the host name in cPanel X (vistapanel) home page (with in the left sidebar the section Stats, Account Details & Server Information) in the section Databases (in main section) clicking MySQL Databases lead to a page labeled MySQL Databases, in the section Current Databases there's a table which should have the DB name in the column MySQL DB Name, the corresponding column (of the same row) MySQL Host Name contain what should replace the default localhost. Mine was sql300.byethost6.com.

zhangxiaofei’s picture

I met this question!