Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on OSX

前端 未结 14 1494
情深已故
情深已故 2020-11-27 09:30

I have a standard Rails3 environment, RVM 1.2.9, Rails 3.0.5, Ruby 1.9.2p180, MySQL2 Gem 0.2.7, mysql-5.5.10-osx10.6-x86_64

Error I get when running rake db:m

相关标签:
14条回答
  • 2020-11-27 10:14

    On my machine mysqld service stopped that's why it was giving me the same problem.

    1:- Go to terminal and type

    sudo service mysqld restart
    

    This will restart the mysqld service and create a new sock file on the required location.

    0 讨论(0)
  • 2020-11-27 10:15

    The default location for the MySQL socket on Mac OS X is /var/mysql/mysql.sock.

    0 讨论(0)
  • 2020-11-27 10:17

    I have had the same problem, but none of the answers quite gave a step by step of what I needed to do. This error happens because your socket file has not been created yet. All you have to do is:

    1. Start you mysql server, so your /tmp/mysql.sock is created, to do that you run: mysql server start
    2. Once that is done, go to your app directory end edit the config/database.yml file and add/edit the socket: /tmp/mysql.sock entry
    3. Run rake:dbmigrate once again and everything should workout fine
    0 讨论(0)
  • 2020-11-27 10:18

    Found it!

    Change host: localhost in config/database.yml to host: 127.0.0.1 to make rails connect over TCP/IP instead of local socket.

    development:
      adapter: mysql2
      host: 127.0.0.1
      username: root
      password: xxxx
      database: xxxx
    
    0 讨论(0)
  • 2020-11-27 10:18

    If you are on Mac OSX,

    The default location for the MySQL Unix socket is different on Mac OS X and Mac OS X Server depending on the installation type you chose

    MySQL Unix Socket Locations on Mac OS X by Installation Type

    • Package Installer from MySQL ------------------/tmp/mysql.sock

    • Tarball from MySQL -------------------------------/tmp/mysql.sock

    • MySQL Bundled with Mac OS X Server -------/var/mysql/mysql.sock

    So just change your database.yml in socket: /tmp/mysql.sock to point to the right place depending on what OS and installation type you are using

    0 讨论(0)
  • 2020-11-27 10:19

    With my installation of MAMP on OSX the MySQL socket is located at /Applications/MAMP/tmp/mysql/mysql.sock. I used locate mysql.sock to find my MySQL socket location.

    So my config/database.yml looks like:

    development:
      adapter: mysql2
      host: localhost
      username: root
      password: xxxx
      database: xxxx
      socket: /Applications/MAMP/tmp/mysql/mysql.sock
    
    0 讨论(0)
提交回复
热议问题