DISQUS

Tech-Recipes: Solve: Can’t connect to local MySQL server through socket /tmp/mysql.sock | MySQL | Tech-Recipes

  • hans gruber · 4 years ago
    This may *sound* like a kludge as this will **CONFIRM** the abovestated steps.

    Simply create a symbolic link under the "/tmp" directory BACK to the "mysql.sock" file. Make sure that it's worldwide read/write-able. To do so would be like this:

    cd /tmp
    ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

    Try it then -- if it is still having trouble, then you might have something else wrong; otherwise, this is because of the RPM installation that you might've used from Red Hat (aka "Fedora").

    Just a friendly hint....cheers!

    hg
  • MarcoGlz · 3 weeks ago
    Wouldn't the link be removed at server reboot and the problem appear again??

    I had the same problem but it is because my.cnf was not in the default locations

    CLIENT:
    Default options are read from the following files in the given order:
    /etc/my.cnf ~/.my.cnf /usr/local/mysql/etc/my.cnf

    So even when I added the [client] section I got the same error, so I did a link

    #ln -s /my/cnf/file_location/my.cnf /etc/my.cnf

    And it worked great.
  • Paradigm · 4 years ago
    Also, this message could mean the the deamon mysqld isn't running, and no socket file has been created.
  • Anonymous · 2 years ago
    For SUSE uers (maybe others)..

    :: QUOTE ::
    YaST stops a little short of fully installing MySQL. ...

    I checked the /var/lib/mysql/ directory only to find it empty! This directory is supposed to include the MySQL foundation files that are necessary to make it all work.

    I found the following in the MySQL documentation:

    1. Log in as the root user. ("Start" => "Switch User")
    2. Open a terminal window (the icon that looks like a monitor behind a clamshell).
    3. Type "cd /bin" enter (no quotes). :: usually not nessecary ::
    4. Type "mysql_install_db --user=mysql

    This is from: http://www.novell.com/coolsolutions/feature/595...
  • Anonymous · 1 year ago
    <ul id="quote"><h6>hans gruber wrote:</h6>This may *sound* like a kludge as this will **CONFIRM** the abovestated steps.

    Simply create a symbolic link under the "/tmp" directory BACK to the "mysql.sock" file. Make sure that it's worldwide read/write-able. To do so would be like this:

    cd /tmp
    ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

    Try it then -- if it is still having trouble, then you might have something else wrong; otherwise, this is because of the RPM installation that you might've used from Red Hat (aka "Fedora").

    Just a friendly hint....cheers!

    hg</ul>

    Actually, this helped tremendously. I am on OS X 10.5 and I don't seem to have a my.cnf file. However, when I tried to connect to mysql, I got the norm error can't connect to . . . through socket . . . "/var/mysql/mysql.sock". A quick search confirmed that /var/mysql/mysql.sock did not exist. I would not have known how to fix this (as a copy paste would not have worked for a socket file) so your post was the solution I implemented, creating a link in /var/mysql that targeted the /tmp/mysql.sock


    Thanks!

    crab
  • jondear · 11 months ago
    Should I be able to connect to MySQL over my LAN? I am running MAMP on Tiger, and can connect using MAMP's built in tools, but preferred the look of Sequel Pro, which I can use to connect with MySQL on the local machine using LocalHost, root user, and password, port 8889 and Socket: /Applications/MAMP/tmp/mysql/mysql.sock. However when I try to connect to that Mac from another on the LAN, which works to MAMP fine via http://192.168.0.4:8888/ It says Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2). I'm confused. MAMP's using port 8888, and MySQL's using port 8889. How can I get pass both in the URL? Or am I all wrong here? Any suggestions?
  • arun · 10 months ago
    I found the following in the MySQL documentation:

    1. Log in as the root user. ("Start" => "Switch User")
    2. Open a terminal window (the icon that looks like a monitor behind a clamshell).
    3. Type "cd /bin" enter (no quotes). :: usually not nessecary ::
    4. Type "mysql_install_db --user=mysql

    This is from: http://www.novell.com/coolsolutions/feature/595...
  • obaid · 9 months ago
    can this type of error be generated by something like:
    mysql_fetch_assoc();
    /*as you can see the resource parameter of mysql_fetch_assoc(<$resource>)*/ is missing
    do help please...!!!
  • gogster · 8 months ago
    I am on client side. I can't change serwer settings. Can send php scripts only! It would be usefull if it will be my own serwer, but it isnt.. So your's advice is useless..

    The reason fo client is bad serwer name in "mysql_connect" function. For example database is:
    "http://abc.def.ghi.com/mysql5/"
    so you should use it properly like this:

    mysql_connect("abc.def.ghi.com",...);

    insted of not properly like this:

    mysql_connect("http://abc.def.ghi.com/mysql5/",...);
  • gogster · 8 months ago
    of course in this problem command:

    mysql_connect("localhost",...);

    not work
  • David C. Rankin, J.D.,P.E. · 5 months ago
    Excellent nugget of information:

    It came in real handy when the geniouses at opensuse broke an update of mysql to mysql-5.1.34-29.1 by putting the mysql.sock and mysqld.pid in /var/run/mysql instead of /var/lib/mysql as normal. Great quick fix was found here. In addition to /etc/my.cnf, the init script at /usr/sbin/rcmysql needed to be fixed as well.

    Thanks
  • Steven Sheffey · 4 months ago
    Hi guys, I to have this problem and I'm new to mySQL and PHP. Where are you guys locating all these directories such as: /var/lib/mysql or /usr/local/mysql/data ?
  • JEME · 4 months ago
    Good day qmchenry,

    I try with de line:
    mysql --socket=/var/lib/mysql/mysql.sock ...

    but now the terminal list this error:

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


    would you can help me
  • NikoJr · 1 month ago
    Man u have saved my life hehehe... very useful.

    Thanku very much