dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

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

This is a discussion on Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46) - mysql ; 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"; ...


Home > Database Forum > Other Databases > mysql > Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 08-23-2007, 11:48 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

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

Reply With Quote
  #2  
Old 08-23-2007, 12:14 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Can't connect to local MySQL server through socket '/tmp/mysql.sock'(46)

laredotornado@zipmail.com wrote:
> 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
>


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.
jstucklex@attglobal.net
==================
Reply With Quote
  #3  
Old 08-23-2007, 12:22 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

On Thu, 23 Aug 2007 08:48:04 -0700, laredotornado@zipmail.com wrote:
> 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?


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
Reply With Quote
  #4  
Old 08-23-2007, 01:01 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Can't connect to local MySQL server through socket '/tmp/mysql.sock'(46)

Peter H. Coffin wrote:
> On Thu, 23 Aug 2007 08:48:04 -0700, laredotornado@zipmail.com wrote:
>> 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?

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


Peter,

See the subject line...


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #5  
Old 08-23-2007, 03:37 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

"laredotornado@zipmail.com" wrote in
news:1187884084.643085.40620@l22g2000prc.googlegro ups.com:

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


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

http://help.yahoo.com/help/us/geo/mysql/mysql-11.html

and in general, http://help.yahoo.com/help/us/geo/mysql/
Reply With Quote
  #6  
Old 10-23-2009, 07:07 AM
Database Newbie
 
Join Date: Oct 2009
Posts: 1
masrteextol is on a distinguished road
Default Re: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

databasehost="localhost" tochange databasehost="mysql"


that is enough

in your config file you have to use mysql instead of localhost.
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 08:02 AM.