Reputation: 11627
I am running some rails app on osx, but when I launch a rails generate
command type, I get this message :
/$root/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error)
For info, my mamp server is running, and the connection must pass through /Applications/MAMP/Library/bin/mysql
, so I aliased it by setting in my bash profile :
alias mysql="/Applications/MAMP/Library/bin/mysql"
Btw, what is weird, is that my rails s
command works perfectly, so my app can connect to the apache server in that case
Upvotes: 1
Views: 1145
Reputation: 11627
So the trick was to simply /tmp/mysql.sock
to /Applications/MAMP/tmp/mysql/mysql.sock
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Upvotes: 4
Reputation: 1399
The error indicates that "mysql is not started/running". From what you describe, looks like the new location pointed to the alias has no mysql or its mysql is not started.
Look my.cnf file with the correct parameters in the new location: /Applications/MAMP/Library/bin/mysql
Another trick is to list your running processes and look for mysql. Also, are you sure, "rails c" is not using the sqlite3 vs mysql?
Updated:
*Courtesy of @bfavaretto MySQL my.cnf location on OS X?
By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values. To set up your own my.cnf, you could just create a file straight in /etc.
OS X provides example configuration files at /usr/local/mysql/support-files/
Update:
Take a look at this:
https://stackoverflow.com/questions/4788381/getting-cant-connect-through-socket-tmp-mysql-when-installing-mysql-on-m
Upvotes: 1