11

I have been working on this all day long, and I need some help.

I am trying to setup the mysql database for a RoR project I'm working on from github.

When I try to setup the db in the terminal, I get the following error:

Eric-MacBook:~ eric$ cd ~/review_rocket
Eric-MacBook:review_rocket eric$ rake db:setup
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

I have looked through 20 questions on SO, and none have been able to help me solve my problem.

The database is up and running, and the database.yml is set up too.

I am currently going a little mad... please... help...before it's too late.

UPDATE: I just looked at my installed gems, and for some reason it's showing mysql2 (see below)

Eric-Reas-MacBook:~ ericrea$ gem list

*** LOCAL GEMS ***

multi_json (1.8.2)
mysql2 (0.3.13)
net-sftp (2.1.2) 

That seems a little odd to me...

Update: Here is what my database.yml is looking like:

common: &common
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  user_name: xxxx
  password: xxxx
  socket: /var/run/mysqld/mysqld.sock

development:
  <<: *common
  database: dev_review_rocket

# Warning: The database defined as "money_tracker_test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *common
  database: test_review_rocket

production:
  <<: *common
  database: prod_review_rocket

UPDATE: Now getting weird errors when trying to reinstall mysql with homebrew (see below):

$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.13.mountain_lion.bottle.1.tar.gz
==> Pouring mysql-5.6.13.mountain_lion.bottle.1.tar.gz
==> /usr/local/Cellar/mysql/5.6.13/bin/mysql_install_db --verbose --user=ericrea
2013-10-22 18:32:41 56901 [Note] InnoDB: FTS optimize thread exiting.
2013-10-22 18:32:41 56901 [Note] InnoDB: Starting shutdown...
2013-10-22 18:32:42 56901 [Note] InnoDB: Shutdown completed; log sequence number 1626067
2013-10-22 18:32:42 56901 [Note] /usr/local/Cellar/mysql/5.6.13/bin/mysqld: Shutdown complete

Warning: mysql post_install failed. Rerun with `brew postinstall mysql`.
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> Summary
  /usr/local/Cellar/mysql/5.6.13: 9382 files, 354M
Eric-Reas-MacBook:~ ericrea$ brew postinstall mysql
==> /usr/local/Cellar/mysql/5.6.13/bin/mysql_install_db --verbose --user=ericrea
2013-10-22 18:33:22 57135 [Note] InnoDB: FTS optimize thread exiting.
2013-10-22 18:33:22 57135 [Note] InnoDB: Starting shutdown...
2013-10-22 18:33:23 57135 [Note] InnoDB: Shutdown completed; log sequence number 1626087
2013-10-22 18:33:23 57135 [Note] /usr/local/Cellar/mysql/5.6.13/bin/mysqld: Shutdown complete


READ THIS: https://github.com/mxcl/homebrew/wiki/troubleshooting

These open issues may also help:
    https://github.com/mxcl/homebrew/issues/22021
    https://github.com/mxcl/homebrew/pull/22480
NM Pennypacker
  • 6,704
  • 11
  • 36
  • 38
novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103

6 Answers6

21

I ended up figuring this one out.

I ran the following command:

$ mysqladmin variables | grep socket

Which returned:

| performance_schema_max_socket_classes                  | 12                                                                                                                                                                                                                                                                                                                                               |
| performance_schema_max_socket_instances                | 323                                                                                                                                                                                                                                                                                                                                              |
| socket                                                 | /tmp/mysql.sock

Then I checked the socket location in my database.yml file and it was wrong:

It was wrong. After changing it to the right socket location everything worked like a charm. I hope this helps someone in the future.

novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103
13

You have to start the mysql server

mysql.server start

and I think you may be looking for

rake db:migrate
NM Pennypacker
  • 6,704
  • 11
  • 36
  • 38
  • 1
    Holy shiz, I'm really struggling with this today: Got an error: ``$ mysql.server start Starting MySQL ........ ERROR! The server quit without updating PID file (/usr/local/var/mysql/Eric-MacBook.local.pid).`` – novicePrgrmr Oct 23 '13 at 00:19
  • Try sudo mysql.server start – NM Pennypacker Oct 23 '13 at 00:22
  • just did, same result. – novicePrgrmr Oct 23 '13 at 00:24
  • Try sudo chown -R _mysql /usr/local/var/mysql – NM Pennypacker Oct 23 '13 at 00:24
  • No dice, same issue. Should I just uninstall mysql and reinstall? – novicePrgrmr Oct 23 '13 at 00:26
  • See this issue: http://stackoverflow.com/questions/4963171/mysql-server-startup-error-the-server-quit-without-updating-pid-file – NM Pennypacker Oct 23 '13 at 00:27
  • Ok, I'll do that and then try ``mysql.server start`` again and let you know. – novicePrgrmr Oct 23 '13 at 00:29
  • What is the status of the mysql service? You can check with sudo service mysql status – Teddy Oct 23 '13 at 00:35
  • Just got some really weird errors with installing mysql with homebrew (posted above in the question). I feel like I should just uninstall any and all instances of mysql on my computer and start again or something. I have obviously messed things up bad. Thank you so much for you help, I am so grateful for smart people like you who are willing to help out guys like me. – novicePrgrmr Oct 23 '13 at 00:43
  • 2
    I'm no smarter than you. I've just been through this kind of stuff before. Glad I could help. Let me know if you need to open a chat to figure this out. – NM Pennypacker Oct 23 '13 at 00:57
4

To solve this error first find your socket file, run the following commands in terminal

mysqladmin variables | grep socket

For me, this gives:

| socket              | /var/run/mysqld/mysqld.sock

Then, add a line to your config/database.yml:

development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock

This will solve this problem.

Praveen George
  • 9,237
  • 4
  • 26
  • 53
3

Try and find your MySQL's my.cnf file. On a typical Ubuntu server it is at: /etc/mysql/my.cnf

Open the file and make sure that the socket variable i.e. socket = /var/run/mysqld/mysqld.sock

corresponds to your socket value in your apps' database.yml

Werner Bihl
  • 196
  • 2
  • 7
1

Just simply run

mysql server.restart

to restart the server. This fixed this issue for me.

Andrew
  • 15,357
  • 6
  • 66
  • 101
Rio Dermawan
  • 133
  • 1
  • 4
0

I had similar issue (also using Brew and also getting PID file problem) with mysql and my PHP app. It started after I updated the OSX to Mavericks, probably the system update overrided my settings. Strangely, everything regarding mysql started to work again after I recreated /etc/php.ini and set proper socket address pointing to /tmp/mysql.sock. Maybe it'll help someone googling for this.

borgo
  • 21
  • 3