# Can't connect to local MySQL server through socket '/tmp/mysql.sock'

**URL:** <https://forum.kirupa.com/t/cant-connect-to-local-mysql-server-through-socket-tmp-mysql-sock/311613>\
**Category:** programming\
**Created:** [July 12, 2010, 2:33pm UTC](https://forum.kirupa.com/t/cant-connect-to-local-mysql-server-through-socket-tmp-mysql-sock/311613 "2010-07-12T14:33:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndesign\_ie](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@ndesign\_ie](https://forum.kirupa.com/u/ndesign_ie)\
**Post date:** [July 12, 2010, 2:33pm UTC](https://forum.kirupa.com/t/cant-connect-to-local-mysql-server-through-socket-tmp-mysql-sock/311613/1 "2010-07-12T14:33:24Z")

</div>

Hi All,

have a headache inflicting problem (Warnings)  
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’  
and then:  
A link to the server could not be established

right, code is below, host and db name changed for this forum purpose.

All i want this script to do is login(works), display the first field data in the table, edit it and save it back. Simple? i thought so too but now nothing works. ■■■■ socks. Mysql has given me the right place for the mysql.sock but it still can’t find it. i know the code is not 100% but the sql statements come out as they should be, but they dont run.

Help! Please!

\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)”\>  
\<html xmlns=“[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)”\>  
\<head\>  
\<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /\>  
\<title\>data editor\</title\>  
\</head\>\<?php

$user = $\_REQUEST[user];  
$pass = $\_REQUEST[pass];  
global $con;  
global $dbname;  
$dbname = “DbStore”;  
if($\_REQUEST[disconnect]==“disconnect”){  
echo(“disconnected \<br/\>”);  
unset($\_REQUEST);  
session\_unset();  
session\_destroy();  
}  
if($\_SESSION[LOGIN] || ( $user )){  
echo(“log in \<br/\> “);  
if(!$user) $user = $\_SESSION[LOGIN][USER];  
if(!$pass) $pass = $\_SESSION[LOGIN][PASS];  
$con = @mysql\_connect(‘host’, $user, $pass) or die(”\<center\>\<b\>Connection Error, norm\</b\>\</center\>\<br/\>”);  
echo($dbname."\<br/\>");  
mysql\_select\_db($dbname,$con)or die(“damn, no database!\<br/\>”);  
echo(“database found\<br/\>”);  
}  
if ($con || $\_REQUEST[cmdSave]){  
$\_SESSION[LOGIN][USER] = $user;  
$\_SESSION[LOGIN][PASS] = $pass;  
if ($\_REQUEST[cmdSave]){  
echo(“updater \<br/\> “);  
updater();  
}else{  
echo(“editor \<br/\>”);  
editor();  
}  
}else{  
echo(“log on, back to square 1 \<br/\>”);  
logontome();  
}  
//  
// Operational functions  
//  
function updater(){  
echo(“past database now updating\<br/\>”);  
$sql1 = “UPDATE ‘bandinfo’ SET band =’”.$\_POST[‘txtband’].”’;”;  
echo($sql1."\<br/\>");  
$sql2 = “UPDATE ‘gigs’ SET giglist =’”.$\_POST[‘txtgigs’]."’;" ;  
echo($sql2."\<br/\>");  
$sql3 = “UPDATE ‘newsitems’ SET leftside =’”.$\_POST[‘txtlnews’]."’, rightside =’".$\_POST[‘txtrnews’]."’;" ;  
echo($sql3."\<br/\>");

```
mysql_query($sql1) or die("SQL for band Update failed&lt;br/&gt;".mysql_error());
mysql_query($sql2) or die("SQL for gigs Update failed&lt;br/&gt;".mysql_error());
mysql_query($sql3) or die("SQL for news Update failed&lt;br/&gt;".mysql_error());
dataDisp();

```

}

function logontome(){  
echo("  
\<form method=POST action=dataedit.php\>  
\<table width=300 class= dbs align=left border=0 bgcolor=#f1f1f1\>  
\<tr\>  
\<td\>User\</td\>\<td\>\<input type=‘text’ name=‘user’ maxlength=100 size=20 style=‘width:100%’\>\</td\>  
\</tr\>  
\<tr\>  
\<td\>Pass\</td\>\<td\>\<input type=‘password’ name=‘pass’ maxlength=100 size=20 style=‘width:100%’\>\</td\>  
\</tr\>  
\<tr\>  
\<td align=center colspan=2\>\<input type=submit value=LogIn name=connect class=buttons\>\</td\>  
\</tr\>  
\</table\>  
\</form\>  
“);  
}  
function editor(){  
echo(“Editor \<br/\>”);  
echo($dbname .” \<br/\>");  
$result1 = mysql\_query(“SELECT ‘band’ FROM ‘bandinfo’ “);  
$result2 = mysql\_query(“SELECT ‘giglist’ FROM ‘gigs’ “);  
$result3 = mysql\_query(“SELECT ‘leftside’ , ‘rightside’ FROM ‘newsitems’ “);  
echo($result1.”\<br/\>”);  
echo($result2.”\<br/\>”);  
echo($result3.”\<br/\>”);  
echo("  
\<form method=POST action=dataedit.php\>  
\<table class= dbs align=center border=0 bgcolor=#f1f1f1\>  
\<tr\>  
\<td width=‘111’ align=‘left’ valign=‘top’\>Band Info\</td\>  
\<td width=‘343’\>\<textarea name=‘txtband’ cols=‘50’ rows=‘14’ value=’" . $result1 . “’\>\</textarea\>\</td\>  
\<td width=‘114’ align=‘left’ valign=‘top’\>Gigs\</td\>  
\<td width=‘334’\>\<textarea name=‘txtgigs’ cols=‘50’ rows=‘14’value=’” . $result2 . “’\>\</textarea\>\</td\>  
\</tr\>  
\<tr\>  
\<td align=‘left’ valign=‘top’\>News - Left Side\</td\>  
\<td\>\<textarea name=‘txtlnews’ cols=‘50’ rows=‘14’value=’” . $result3 . “’\>\</textarea\>\</td\>  
\<td align=‘left’ valign=‘top’\>News - Right Side \</td\>  
\<td\>\<textarea name=‘txtrnews’ cols=‘50’ rows=‘14’value=’” . $result3 . “’\>\</textarea\>\</td\>  
\</tr\>  
\<tr\>  
\<td align=right colspan=5\>\<input type=submit value=Save name=cmdSave class=buttons\>\</td\>  
\</tr\>  
\</table\>  
\</form\>  
“);  
}  
function dataDisp(){  
echo(“Data Display \<br/\>”);  
$result = mysql\_query(“SELECT ‘bandinfo’.‘band’ , ‘gigs’.‘giglist’ , ‘newsitems’.‘leftside’ , ‘newsitems’.‘rightside’ FROM bandinfo, gigs, newsitems LIMIT 0 , 1”);  
echo($result .”\<br/\>” );  
echo($result[‘band’] ." , see nothing?");  
echo("  
\<form method=POST action=dataedit.php\>  
\<table class= dbs align=center border=0 bgcolor=#f1f1f1\>  
\<tr\>  
\<td width=‘111’ align=‘left’ valign=‘top’\>Band Info\</td\>  
\<td width=‘343’\>\<textarea name=‘txtband’ cols=‘50’ rows=‘14’ value=’" . $result[‘bandinfo`.`band’] . “’\>\</textarea\>\</td\>  
\<td width=‘114’ align=‘left’ valign=‘top’\>Gigs\</td\>  
\<td width=‘334’\>\<textarea name=‘txtgigs’ cols=‘50’ rows=‘14’value=’” . $result[`gigs`.‘giglist’] . “’\>\</textarea\>\</td\>  
\</tr\>  
\<tr\>  
\<td align=‘left’ valign=‘top’\>News - Left Side\</td\>  
\<td\>\<textarea name=‘txtlnews’ cols=‘50’ rows=‘14’value=’” . $result[‘leftside’] . “’\>\</textarea\>\</td\>  
\<td align=‘left’ valign=‘top’\>News - Right Side \</td\>  
\<td\>\<textarea name=‘txtrnews’ cols=‘50’ rows=‘14’value=’” . $result[‘rightside’] . "’\>\</textarea\>\</td\>  
\</tr\>  
\<tr\>  
\<td align=right colspan=5\>\<input type=submit value=Save name=cmdSave class=buttons\>\</td\>  
\</tr\>  
\</table\>  
\</form\>  
");  
}  
?\>  
\<body\>  
\</body\>  
\</html\>
