0

I am new to using Mina for a Rails 4 app deployment. It is a very simple application using MySQL. The server is Ubuntu 14.04 on Digital Ocean. I have MySQL installed on the server and can login with the mysql CLI on the server using the credentials that are in my database.yml. However, when Mina is trying to run a rake db:migrate, it fails with the following:

-----> Migrating database
   $ RAILS_ENV="staging" bundle exec rake db:migrate
   rake aborted!
   Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)

I verified the socket location in /etc/mysqld/my.cnf is /var/run/mysqld/mysql.sock and this matches the database.yml configuration as well.

Why?

andrunix
  • 1,704
  • 1
  • 14
  • 23
  • You can determine your mysql.sock by following this tutorial [location of mysql.sock][1] [1]: http://stackoverflow.com/questions/5499035/ruby-on-rails-3-cant-connect-to-local-mysql-server-through-socket-tmp-mysql-s – akbarbin Sep 20 '15 at 10:02
  • Indeed, this gives me: /var/run/mysqld/mysqld.sock which is what is in my config and present on the filesystem. – andrunix Sep 21 '15 at 12:18

1 Answers1

0

These are steps to fix your problem:

Step 1: change you host into 127.0.0.1

staging:
  adapter: mysql2
  host: 127.0.0.1
  username: root
  password: xxxx
  database: xxxx
  socket: your-location-socket

Step 2: It seems like you have 2 connections into you server MySql. To find your socket file location do this:

mysqladmin variables | grep socket

for me gives:

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' exists!

or

mysql --help 

I get this error because I installed XAMPP in my OS X Version 10.9.5 for PHP application. Choose one of the default socket location here.

I choose for default rails apps:

socket: /tmp/mysql.sock

For my PHP apps, I install XAMPP so I set my socket here:

socket: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

OTHERS Socket Location in OS X

For MAMPP:

socket: /Applications/MAMP/tmp/mysql/mysql.sock

For Package Installer from MySQL:

socket: /tmp/mysql.sock

For MySQL Bundled with Mac OS X Server:

socket: /var/mysql/mysql.sock

For Ubuntu:

socket: /var/run/mysqld/mysql.sock

For details information ruby-on-rails-3-cant-connect-to-local-mysql-server-through-socket-tmp-mysql-s

Step 3: If all those setting doesn't work you can remove your socket location:

staging:
  # socket: /var/run/mysqld/mysql.sock

I hope this help you.

Community
  • 1
  • 1
akbarbin
  • 4,985
  • 1
  • 28
  • 31