mysql.h is missing .... (Ruby on Rails, OSX)

12,486

Solution 1

Using a package manager like Homebrew or MacPorts makes it fairly straight-forward to fix this. The binary distribution of MySQL direct from Oracle and the one bundled with OS X itself does not have the development headers, of which mysql.h is one of them.

Homebrew would fix it like this:

brew install mysql

MacPorts is very similar:

sudo port install mysql

Both of these install libraries, a command-line client and the associated development headers for the libraries. Enabling the server is optional.

As an alternative, you can get the source direct from Apple and install it whatever way you see fit.

Generally Homebrew is the best way to go.

Solution 2

What worked for me in Mountain Lion Rails install(using Homebrew and RVM) was editing /usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config and removing -Wno-null-conversion -Wno-unused-private-field from cxflags and cxflags options as follows:

Before:

cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

After:

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

After that gem install mysql2 proceeded without hickups

Note: this is probably due to a change introduced to mysql_config after 5.6.10: http://bugs.mysql.com/bug.php?id=69645

Share:
12,486
gadreel
Author by

gadreel

Updated on June 05, 2022

Comments

  • gadreel
    gadreel almost 2 years

    I tried several ideas ... none of them worked ... I'm just trying to install mysql2 as a gem. My mysql is working, but every time my system says, that mysql.h is missing ... Has someone an idea? It's very frustrating now ...

    I'm using osx 10.8.3, ruby 1.9.3, rails 3.2.13 and home-brew.

        gem install mysql2 -v '0.3.11'
    Building native extensions.  This could take a while...
    ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.
    
            /Users/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
    checking for rb_thread_blocking_region()... yes
    checking for rb_wait_for_single_fd()... yes
    checking for mysql.h... no
    checking for mysql/mysql.h... no
    -----
    mysql.h is missing.  please check your installation of mysql and try again.
    -----
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.
    
    Provided configuration options:
        --with-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
        --with-mysql-config
        --without-mysql-config
    
        file `which mysql`
        /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
    
  • tadman
    tadman almost 11 years
    The question specifically states OS X.
  • gadreel
    gadreel almost 11 years
    I did this, but it didn't work. I reinstalled port and then mysql5. Now I have this error: Users/gadreel/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/l‌​ib/mysql2/client.rb:‌​44:in `connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error)
  • sebastiangeiger
    sebastiangeiger almost 11 years
    Works for me too, seems to be a fairly recent problem, I just reinstalled my computer.
  • mrm
    mrm almost 11 years
    WFM. Note that you don't need to reinstall mysql. Just edit the mysql_config, and gem install mysql2. Thanks!
  • okliv
    okliv almost 11 years
    just for people who didn't use brew to install mysql: mysql_config in my case was here: /usr/local/mysql-5.6.12-osx10.7-x86_64/bin
  • Saifis
    Saifis almost 11 years
    It worked just fine with the community server dmg download. You are a god sir.
  • Andy Waite
    Andy Waite almost 11 years
    Also worked for me. Would appreciate an explanation of why this is necessary though.
  • Vlad Gurovich
    Vlad Gurovich almost 11 years
    @AndyWaite I added a link to what I believe caused this issue
  • Alex
    Alex over 6 years
    sudo port install mysql does not work. Closest command is, to install the latest version of mysql is: sudo port install mysql55; however, this does not create mysql.h. The port mysql55-server also does not include it. Which port would?
  • tadman
    tadman over 6 years
    @Alex MacPorts has fallen out of favour with the community so I'm not sure what condition it's in. The vast majority of devs are using Homebrew. Switching over can be a bit of a hassle, but this might be less hassle than getting MacPorts working.
  • Alex
    Alex over 6 years
    The problem is, I typically tend to run as root, and then Homebrew tends to fail, saying I have to run it as a regular user. So I have to log out, log back in, etc.-- so I strongly prefer to use (any) tool that can run as root.
  • tadman
    tadman over 6 years
    Running as root is a bad habit and one that you should immediately curtail. There's a reason HomeBrew is badgering you about that.
  • Alex
    Alex over 6 years
    My view is, it shouldn't be the responsibility of Homebrew, with their clinking mugs, to tell me I shouldn't be running as root. My company tells me what to do, and what not to do, and I'm sure they know better. But anyways, if macports no longer works for this, then maybe you could at least remove it from your answer.
  • tadman
    tadman over 6 years
    If your company is telling you to run as root I have serious questions about your company. It's the computer equivalent of running with scissors and I'd challenge you to find any security expert that thinks it's a good idea. This answer is from 2013, you can't expect all advice from that era to be up to date.