Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:53:49+00:00 2026-06-07T13:53:49+00:00

I’m on a Mac and used brew to install an updated MySQL. In an

  • 0

I’m on a Mac and used brew to install an updated MySQL. In an effort to streamline my local database creation, I took the password off my local root user (I know, I know), and after creating a new Rails app (rails new myapp -d mysql), should just be able to run rake db:create, right?

However, despite having /etc/my.cnf set to define the standard mysql.sock location…

[mysqld]
socket=/usr/local/var/mysql/mysql.sock

[client]
socket=/usr/local/var/mysql/mysql.sock

… Rails still won’t use the newly defined mysql.sock file on a rake db:create:

rake db:create
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"delayed_jobs_development", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost"}, charset: , collation: 

Running mysqladmin variables lists the correct socket file location, as does mysql --help. I’ve restarted the MySQL server and even recreated the Rails app.

So my question: What else could be defaulting the socket file to /tmp/mysql.sock, or is there an alternate, preferably global, config file where I could specify its location that the rake task will honor? Could the rake task be calling a different commandline MySQL tool that uses a different config file?

Obviously, I could either create a symlink from the /tmp location to my real location, or edit my database.yml file to refer to it. I understand how to get Rails to talk to the DB server correctly, but the point is to have the proper defaults set up once, so any future Rails app I create locally is good to go without extra edits (/tmp/mysql.sock gets cleared on reboot).

In fact, I’m not even sure why it’s trying to connect via the socket file at all, since my database.yml file tells it to use the hostname:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: myapp_development
  pool: 5
  username: root
  password:
  host: localhost
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:53:50+00:00Added an answer on June 7, 2026 at 1:53 pm

    As the MySQL documentation says, /tmp/mysql.sock is the default location for the socket file. This is also what rails defaults to (more below).

    As you mentioned, you can always set the socket (the one you configured and that is returned by mysqladmin variables) explicitly in your database.yml file:

    socket: /usr/local/var/mysql/mysql.sock
    

    I think the connection is made via the socket file as you set host: localhost. If you change that to 127.0.0.1, the connection should by made over TCP/IP.

    I found rather old information (a really old version of the mysql adapter and a blog entry from 2007) which implies that the MYSQL_UNIX_ADDR environment variable is used in resolving the socket. Also see this comment on GitHub by the developer of Ruby/MySQL, in which he says to set the MYSQL_UNIX_PORT variable instead. A third env variable is MYSQL_SOCKET mentioned in the source of the Ruby/MySQL connector.

    export MYSQL_UNIX_ADDR=/usr/local/var/mysql/mysql.sock
    export MYSQL_UNIX_PORT=/usr/local/var/mysql/mysql.sock
    export MYSQL_SOCKET=/usr/local/var/mysql/mysql.sock
    

    I do not know if these variables get evaluated somewhere along the way. Still, you could try them out.

    Right now, rails mysql_adapter.rb says that the configured socket is used and that it defaults to /tmp/mysql.sock (set in app_generator.rb). No other locations seem to get checked. I did not found anything else in the default Ruby/MySQL adapter used by rails.

    So basically – without being an expert on this topic – I don’t think there is a way to set a global default location for the MySQL socket file that gets evaluated by rails or the used default adapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.