Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Post by laredotorn » Sat, 25 Aug 2007 00:48:04


Hi,

Our hosting company is Yahoo! and we have a MySQL 4.1.6 database.
phpMyAdmin 2.6.3 is installed and I can manipulate the db fine through
that. However, when I try and connect through a PHP file using

$db_hostname = "localhost";
$db_socket = "";

$mysql_host = $db_hostname;
if (!empty($db_socket))
$mysql_host .= ":$db_socket";
$db_name = "mydb";
$db_user = "myuser";
$db_password = "mypass";

// Connect
mysql_connect($mysql_host, $db_user, $db_password) or die("Can't
connect to MySQL: '" . mysql_error() . "'");

I get the above error. How can I fix this?

Thanks, - Dave
 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Post by Jerry Stuc » Sat, 25 Aug 2007 01:14:20


First of all, you shouldn't need the socket. Just use 'localhost'.

Does this work?

$result = mysql_connect('localhost', 'myuser', 'mypass');
if (!$result)
echo "Unable to connect: " . mysql_error();
else {
/// do stuff

(die() is not good to use in a production system - handle your errors
more gracefully!).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
XXXX@XXXXX.COM
==================

 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Post by Peter H. C » Sat, 25 Aug 2007 01:22:23


Which above error? I see code, but no error. What does the mysql_error()
function actually spit out?

--
6. I will not gloat over my enemies' predicament before killing them.
--Peter Anspach's list of things to do as an Evil Overlord
 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Post by Jerry Stuc » Sat, 25 Aug 2007 02:00:49


Peter,

See the subject line...


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
XXXX@XXXXX.COM
==================
 
 
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Post by Good Ma » Sat, 25 Aug 2007 04:36:38

" XXXX@XXXXX.COM " < XXXX@XXXXX.COM > wrote in



I'm pretty sure Yahoo has a tech support page on how to connect to
databases... well in fact i'm positive

http://www.yqcomputer.com/

and in general, http://www.yqcomputer.com/