mysqlruby-on-railsrubyampps

Use MySQL from AMPPS with Rails


I'm trying to use Rails with the MySQL bin from Ampps, but when I run the command rails generate scaffold User name:string email:string I get the following error:

dyld: lazy symbol binding failed: Symbol not found: _mysql_server_init
Referenced from: /Users/myusername/.rvm/gems/ruby-2.2.1/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_server_init
  Referenced from: /Users/myusername/.rvm/gems/ruby-2.2.1/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle
  Expected in: flat namespace

I have already configured Ampps Mysql with my environment but I can not managed to make it work with rails, I have the following configurations.

$ which mysql                                          
/Applications/AMPPS/mysql/bin/mysql

$ echo $PATH
/Users/myusername/.rvm/gems/ruby-2.2.1/bin:/Users/myusername/.rvm/gems/ruby-2.2.1@global/bin:/Users/myusername/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myusername/.rvm/gems/ruby-2.2.1/bin:/Users/myusername/.rvm/gems/ruby-2.2.1@global/bin:/Users/myusername/.rvm/rubies/ruby-2.2.1/bin:/Applications/AMPPS/php-5.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myusername/.rvm/bin:/Users/myusername/.rvm/bin:/Applications/AMPPS/mysql/bin

$ ls -l /usr/local/lib/libmy*.dylib 
lrwxr-xr-x  1 myusername  admin  53 Jan  1 19:30 /usr/local/lib/libmysqlclient.18.dylib -> /Applications/AMPPS/mysql/lib/libmysqlclient.18.dylib

I have tried doing commands but with no success:

$ gem install mysql2 -- --with-mysql-lib=/Applications/AMPPS/mysql/lib --with-mysql-include=/Applications/AMPPS/mysql/include --with-mysql-config=/Applications/AMPPS/mysql/bin/mysql_config

And

bundle config build.mysql2 --with-mysql-lib=/Applications/AMPPS/mysql/lib --with-mysql-include=/Applications/AMPPS/mysql/include --with-mysql-config=/Applications/AMPPS/mysql/bin/mysql_config
bundle install

Any ideas?


Solution

  • I downloaded this AMPPS package and did a quick check on the MySQL binary:

    $ file /Volumes/AMPPS/AMPPS/mysql/bin/mysql
    /Volumes/AMPPS/AMPPS/mysql/bin/mysql: Mach-O executable i386
    

    Your 64-bit Ruby install is trying to link to 32-bit MySQL libraries, and is not finding what it's looking for. "Symbol not found" errors are often an indication of an architecture mismatch.

    My advice to you would be to install these programs from a package management system such as MacPorts or Homebrew. I'm partial to MacPorts, so I'll give you instructions for that. I get the impression Homebrew is more popular, but haven't used it myself.

    1. Install Xcode and the Xcode Command Line Tools
    2. Agree to Xcode license in Terminal: sudo xcodebuild -license
    3. Install MacPorts: https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg
    4. Update the port list: sudo port selfupdate
    5. Install away: sudo port install mysql56 rb-rails rb-mysql
    6. Update regularly: sudo port selfupdate && sudo port -uc upgrade outdated

    This way you're getting properly built binaries for your system, you can easily keep them up to date, and you aren't filling your system up with 2 gigabytes of things you aren't necessarily going to use (5 different versions of PHP, a couple of database servers, Perl, Python, etc.) In addition, you also get up-to-date versions of other utilities like Ruby, rather than relying on the outdated version that ships with the operating system.