can't connect to mysql

Discussion in 'General' started by hitokirikensan, Dec 27, 2010.

  1. hitokirikensan

    hitokirikensan New Member

    Hi i'm trying to create a simple comment feature to and have an index.html

    <head><title>Test Page</title></head>
    <h2>Data Collection</h2><p>
    <form action="comments.php" method="post">
    Your Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name = "email"><br>
    Location: <input type="text" name = "location"><br>
    <input type="submit" value="Submit">

    and a comment.php

    mysql_connect("localhost", "root", "password") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());
    mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
    Print "Your information has been successfully added to the database.";

    I get the error "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)"
    I went in my.conf and the socket is pointed to /var/lib/mysql/mysql.sock and i tried copying the sock to /tmp but i still get this error. Is this a litespeed error or a php error?
  2. webizen

    webizen Well-Known Member

    that means /tmp/mysql.sock is defined as default socket (either defined in php.ini or built-in mysql defaults) in your php config. Verify in phpinfo() page. Not an issue with litespeed.

    when copy the socket (not a regular file), you should do ln instead cp. make sure /var/lib/msyql/mysql.sock exists (server started)
    ln /var/lib/mysql/mysql.sock /tmp
    another work around is to define connection socket in your code as follows:
    mysql_connect('localhost:/var/lib/mysql/mysql.sock', "root", "password") or die(mysql_error());
    Last edited: Dec 27, 2010

Share This Page