"Can't connect to local MySQL server" Error

boytroy88 - April 27, 2004 - 01:35

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!

Same problem

tomedo@www.tome... - April 27, 2004 - 02:05

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)

Hmmm...but I don't have any d

boytroy88 - April 27, 2004 - 07:27

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????

Man...I can't believe that it

boytroy88 - April 28, 2004 - 02:01

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????

Sounds like something is wron

Boris Mann - April 28, 2004 - 03:53

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)

I've made sure that the conf.

boytroy88 - April 28, 2004 - 04:22

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???

MySQL problem

Dries - April 28, 2004 - 05:06

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.

Ok...I've talked with my host

boytroy88 - April 29, 2004 - 00:33

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?

Ok...got it to work...it was

boytroy88 - April 30, 2004 - 06:48

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..........

non-standard mysql port

sunil - May 6, 2004 - 10:08

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

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

/var/run/mysqld/mysqld.sock

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?

Add a symbolic link

sellam - December 27, 2004 - 19:05

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.

Reason for this issue SOLVED.

rwelti - May 10, 2006 - 14:57

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

<?php
phpinfo
();
?>
(type ctrl-d here) (output follows:)
phpinfo()
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.

rwelti
Seattle, WA

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

Solution to the problem

jhopkins - August 10, 2006 - 12:57

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:'.

Smiles!

That's the one!

jtizard - September 17, 2006 - 12:09

You're a champ. Thanks

jim, adelaide

Thanks

rzelnik - September 26, 2006 - 15:17

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

Fantastic!

fiprojects - March 2, 2007 - 20:22

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

And if you're using msqli

henryaz - March 22, 2007 - 05:40

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.

127.0.0.1

stephanejais - June 8, 2007 - 17:22

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

hello i have the same

Farouk111 - June 15, 2007 - 20:47

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

The Ultimate Source For Self Understanding and Personal Growth

ini_set('mysql.default_socket

sime - November 14, 2007 - 04:36

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.

what if the mysql connection breaks down periodically

lasarletter - July 1, 2007 - 17:49

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?

thanks

hey, what is the error

Farouk111 - July 13, 2007 - 20:41

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

www.2knowmyself.com

The Ultimate Source For Self Understanding and Personal Growth

solved the problem

lasarletter - July 28, 2007 - 15:41

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

i've never loved a man so

ojay - July 25, 2007 - 23:31

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

adding to the settings seems

darumaki - January 18, 2008 - 21:23

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.

 
 

Drupal is a registered trademark of Dries Buytaert.