Hi! I'm trying to install Drupal-4.4.0 and am getting the following error:
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in {server_directory}/drupal-4.4.0/includes/database.mysql.inc on line 12
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).

I've read through the other post and have edited the conf.php file as suggested but to no avail. I had some problem running phpmyadmin on the server but since I have SSH access I've used that instead. I'm able to load the data (i.e.- using the mysql -u username_drupal < database/database.mysql command) so I'm at lost as to where my problem might be. Thanks for the help!


tomedo@www.tomedo.net’s picture

I'm having the same problem, and i found a way to solve it, but it's very fustrating... I deleted some .module that i don't use, and now the web works.
The first issue before the mysql error was the lost of access to /admin/system/modules, seems that too many .modules block the system.

It worked for me, but the .module limit sucks... anyone knows how to fix that?

(Again, excuse my poor English, hope you understand)

boytroy88’s picture

Hmmm...but I don't have any directory called /admin . All I have under drupal-4.4.0 is database, includes, misc, modules, scripts, and themes. Ok...I see what you are talking about...but how many modules did you remove???

Ok...I tried removing some .modules but it still didn't work....what to do now????

boytroy88’s picture

Man...I can't believe that it's this hard just to install this...I'm sure I'm overlooking something....my postNuke and phpNuke installs wasn't this hard...help, anyone????

oneofakind2727’s picture

I didn't find your English poor at all Tomedo

Boris Mann’s picture

Sounds like something is wrong with your MySQL installation. That error is from MySQL, not from Drupal.

Make sure that the conf.php file is correct.

(I have no idea what the stuff about .modules is -- there is no limit, and if you are running modules designed for the release of Drupal you are using, there should be no problems)

boytroy88’s picture

I've made sure that the conf.php file is correct...as for the MySQL, I'm able to load the database file so I thought that shouldn't be the problem...however I could be wrong...how would I go about checking that problem???

Dries’s picture

This is a MySQL configuration problem, not a Drupal configuration problem.

If your username/password in the configuration file were wrong you'd get another error message. Something along the lines of Access denied for user: 'drupal@localhost' (Using password: YES).

For your problem, please consult http://dev.mysql.com/doc/mysql/en/Can_not_connect_to_server.html: either the MySQL server is not running or you are using an incorrect Unix socket filename or TCP/IP port number when trying to connect to the mysqld server.

boytroy88’s picture

Ok...I've talked with my hosting provider and I'm able to access the db through phpmysqladmin but I'm now I'm getting the "Accessed denied for user" message....what now?

boytroy88’s picture

Ok...got it to work...it was a mysql error although my hosting provider didn't tell me exactly what he did...only that he changed my password to a shorter password and now it works.....hmmmm....now to the problem of getting things configured..........

sunil’s picture

How does one configure drupal to connect to a non-standard

I have a similair problem to the original poster.

Drupal, and other php programs requiring sql access,
cant reach mysqld, because the socket file is in an
unusual place.
Rather than /tmp/mysql.sock , it resides at


I believe that this is the default location for the
socket on debian.

However, I dont want to "fix" the socket problem
by changing the socket, due to fear of breaking
existing client connections.

The database.mysql.inc file seems to include
code that attempts to

"Allow for non-standard MySQL port"

But, this doesn't work in at least my case.

So, how do I get drupal to talk to sqld,
by directing drupal to the correct socket?

sellam’s picture

I have the same problem. After a frustrating hop around the Drupal site fruitlessly trying to find a solution, I decided to fix it myself.

I added a symbolic link to my actual mysql.sock file in the path where Drupal was trying to find it. It seems the default location is in /tmp. So I put a symbolic link at /tmp/mysql.sock that points to my actual mysql.sock file:

lrwxrwxrwx 1 root root 25 Dec 27 10:42 mysql.sock -> /var/lib/mysql/mysql.sock

To create a symbolic link, issue the following command:

ln -s [your actual mysql.sock path and filename] /tmp/mysql.sock

This should fix your problem.

My first fix was to try to hack the Drupal database code but it was more involved than I liked and the changes would have had to be moved to any upgrades of the system. I wish/hope the Drupal guys will put in a feature to allow an alternate socket file to be specified for those unfortunate of us with "non-standard" installations.

rwelti’s picture

First of all making a symlink in /var/mysql to /tmp/mysql.sock WORKED for me.

Now the reason this is needed:

When the PHP you are running was built (whenever/wherever that was) the "configure" command specified various options including where to look for the mySQL socket file.

Look at the output from phpinfo, as in:

$ php


(type ctrl-d here) (output follows:)
PHP Version => 4.4.1

System => Darwin ross-was-imac-g5.local 8.6.0 Darwin Kernel Version 8.6.0: Tue Mar 7 16:58:48 PST 2006; root:xnu-792.6.70.obj~1/RELEASE_PPC Power Macintosh
Build Date => Mar 5 2006 10:28:06
Configure Command => '/SourceCache/apache_mod_php/apache_mod_php-18.4/php/configure' '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql=/usr' '--with-mysql-sock=/var/mysql/mysql.sock'

The last line is the clue. So searching the source code of drupal, and digging deeply into mySQL is not the answer.

Note that there *IS* one other way to solve this:

use "mysqladmin --help"

and read how to change the default socket file to another place, but this could interfere with other clients.

Have fun! Drupal seems really COOL.

Mac users: check out "ecto" for editing drupal blog posts.

Seattle, WA

You know I don't repeat gossip, so listen *closely* --

jhopkins’s picture

I have just installed drupal for the first time and had the same problem. Here is the solution.

Open your sites/settings.php (or sites/YOUR_SITE/settings.php) and add a line like this:

ini_set('mysql.default_socket', '/var/lib/mysql/mysql.sock');

Where '/var/lib/mysql/mysql.sock' is the path to your installation's socket file.

You would typically add this line in the section 'PHP settings:'.


jtizard’s picture

You're a champ. Thanks

jim, adelaide

rzelnik’s picture

This information is very useful for me, thanks.
IMHO this line should be included into settings.php.

fiprojects’s picture

Got to say... Drupal looks sexy but even with years of Unix/Linux behind me, I felt i had to pull teeth out to get it working... first it was the problem not finding reference (until much hair loss) that index.php should be recognised in httpd.conf DirectoryIndex. Then this setting... strangely enough, Drupal 4.7 worked fine for me without the

ini_set('mysql.default_socket', '/var/lib/mysql/mysql.sock');

in the settings file.

Anyway... Many thanks... I have now to decide between Drupal 4.7 or 5.1

henryaz’s picture

You'll need to add the following:

ini_set('mysqli.default_socket', 'YOUR_SOCKET_PATH');

Note that I had to do this in order to get Drupal working on ICDSoft. Thanks for figuring this out -- it led me to figuring this one out.

stephanejais’s picture

Instead of connecting through your socket, you can replace localhost by in the "Host" field of the advanced options.
This worked for me.

Farouk111’s picture

i have the same problem but i cant apply the fix since i dont know where mysqld.sock is, can somebody help?

The Ultimate Source For Self Understanding and Personal Growth

brewermfnyc’s picture

This is the solution that worked for me. I installed drupal in a virtual directory set up through http config and the hosts file - like I do all my development sites. I was already able to connect with phpMyAdmin and various utilities on the websites. Changing the location of the socket as other folks suggested just broke those connections - and drupal still couldn't connect.

Using the IP address ( instead of "localhost" to make the connection is exactly the change I needed.

Try that before you start mucking around in your php.ini file. FWIW...

sime’s picture

ini_set('mysql.default_socket', '/var/run/mysqld/mysqld.sock');

I put this line into sites/default/settings.php, is that right file, but still doesn't work.

nocean’s picture

Excellent -- thanks loads Henryaz. Was having trouble with ICDsoft's setup as well and this worked like a charm.

lasarletter’s picture

My problem is that I get a "can't connect" to the mysql server every now and then. It seems to happen a couple of times a week. Then it goes away.

Any suggestions for this?


Farouk111’s picture

what is the error message that you get when you cant connect?


The Ultimate Source For Self Understanding and Personal Growth

lasarletter’s picture

I solved my database connection problem by migrating the site to a new host.

ojay’s picture

i've never loved a man so much... THANK YOU!

darumaki’s picture

adding to the settings seems pointless if the database isn't working, the settings file should have nothing to do with it, its mysql that has to be connecting otherwise drupal won't work.

captaingeek’s picture

happening here after running fine for a few years. rebooting fixes it but is not a permanant fix.

simurgh’s picture

I am having this same issue too, suddenly, after Drupal has been installed and working for a while. No changes were made. Rebooting does not fix it for me.

mrobo’s picture


saurabh.bhambry’s picture

Facing same error ... though the problem is definitely with the web hosting server...

vikassaxena’s picture

Hello All,

Without doing any changes to my website, I started getting an error that my website is offline. The error that it was showing then was following.

"The mysql error was: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' "

Then after getting in hold of my host admin, I got the issue resolved, this error came as the server was down.

But after getting this one resolved, I could see the main domain, but the sub domain that I was working on, starting receiving the following error

"Forbidden You don't have permission to access / on this server"

Then upon suggestion from my host admin, I checked the .htaccess file and there it was, it had nothing but the following data left

"order deny,allow
deny from all"

I immediately restored my .htaccess file and the issue got resolved for me. You could also trying renaming the file .htaccess to some other name .htaccess1, in case you dont have a backup.

I was so relieved, that I thought of sharing it with you.