SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql::Erro

    MySQL isn't running, and I can't figure out why. I'm not a back-end developer, so I don't know very much about MySQL. The project I'm working on is using Ruby with Rails and a MySQL database. I'm the designer and front-end dev trying to view the files locally using webrick (rails local server). I've done it successfully once before, but I don't know why it isn't working now. This is the error message I get in the terminal when I try to run "rails server" in my project's directory:

    "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql::Error)."

    Since this is a new clone of a project, I went ahead and did a quick bundle install to make sure I had everything I needed. Even after that, I still got the same error message.

    Below shows the web I've woven so far in trying to figure out the above error message.

    From System/usr/local/bin/, I typed:
    Code:
    $sudo ./mysqld_safe &
    [1] 6983
    $./mysqladmin -u root shutdown
    ./mysqladmin: connect to server at 'localhost' failed
    error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' 
    Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
    $ telnet localhost:3306
    localhost:3306: nodename nor servname provided, or not known
    $ telnet 127.0.0.1:3306
    127.0.0.1:3306: nodename nor servname provided, or not known
    $ telnet
    telnet> quit
    That was mostly the Rails developer trying to figure out why it wasn't working. I'm hoping it's useful to you as well. His conclusion was that I needed to create a mysql root password to see if that would fix it because I didn't create one when I first installed mysql. I tried that by doing this:
    Code:
    $mysqladmin -u root password mypassword
    mysqladmin: connect to server at 'localhost' failed
    error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
    Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
    After that, we thought it might be easier to uninstall mysql altogether and reinstall it. Since I initially installed it using Homebrew, I also uninstalled and reinstalled it the same way, which worked just fine.
    Code:
    $ brew uninstall mysql
    $ brew install mysql
    Then we tried this again, which had the same error:
    Code:
    $ telnet 127.0.0.1:3306
    127.0.0.1:3306: nodename nor servname provided, or not known
    $ netstat, however, returned a huge list of things.

    The we tried to start the mysql server:
    Code:
    $ mysql.server start
    Starting MySQL
    .. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Nickis-MacBook-Air.local.pid).
    So we tried to remove that file:
    Code:
    $ rm /usr/local/var/mysql/Nickis-MacBook-Air.local.pid
    rm: /usr/local/var/mysql/Nickis-MacBook-Air.local.pid: No such file or directory
    $ sudo rm /usr/local/var/mysql/Nickis-MacBook-Air.local.pid
    rm: /usr/local/var/mysql/Nickis-MacBook-Air.local.pid: No such file or directory
    That is the error message I'm left with now, but the one at the top I believe is still relevant.

    I really hope someone can help. I'm completely stuck.

  2. #2
    SitePoint Member
    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Figured it out

    Ok, so I figured this out with the help of the back-end dev a day or two after I posted this. This is what we did to fix it:

    Uninstalled mysql with homebrew:
    Code:
    $brew uninstall mysql
    Moved to user/local/Cellar directory:
    Code:
    $cd /
    $cd usr/local/Cellar
    Tried to find all files and clean things up:
    Code:
    $which mysql
    $locate mysql
    $brew cleanup
    $brew remove mysql
    $launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
    $ rm ~/Library/LaunchAgents/com.mysql.mysqld.plist
    I think the $brew cleanup helped a lot.

    Then reinstalled mysql with homebrew:
    Code:
    $brew install mysql
    This is what I think really made it work correctly. I needed to set up the database to run as my user account and start mysql manually.
    Code:
    $unset TMPDIR
    $mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    $mysql.server start
    Starting MySQL
    .. SUCCESS! 
    $mysql -uroot
    mysql> quit
    Bye
    $mkdir -p ~/Library/LaunchAgents
    $cp /usr/local/Cellar/mysql/5.5.20/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
    $launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    And it works! Hope this helps someone out there.

  3. #3
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks for updating with the solution.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •