Development Tip

Rails, MySQL 및 Snow Leopard

yourdevel 2020. 11. 7. 10:34
반응형

Rails, MySQL 및 Snow Leopard


WWDC에서 얻은 디스크를 사용하여 Snow Leopard로 업그레이드했습니다.

내 레일 앱 중 일부를 실행하려고하면 이제 SQL에 대해 불평합니다.

    (in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/

 -- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
  Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

(See full trace by running task with --trace)

나는 이것을 한 번 고쳤을 것이라고 맹세 할 수 있었다. 문제는

sudo gem install mysql

작동하지 않고 오류가 발생합니다.

 Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

/opt/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no


Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

아직 스노우 레오파드의 레일로 작업하기 위해 mysql을 얻은 사람이 있습니까? 그렇다면 설정은 무엇이며 더 나은 방법은 무엇입니까?


나는 똑같은 고통을 겪었습니다 ... 여기 저에게 효과가있는 것이 있습니다.

  1. mysql.com에서 64 비트 MySQL 5.1.37 다운로드 / 설치
  2. 다음 명령을 실행하십시오.

    sudo gem 업데이트 --system

    sudo env ARCHFLAGS = "-arch x86_64"gem install mysql---with-mysql-config = / usr / local / mysql / bin / mysql_config

나는 또한 내 10.5 일 동안 떠 다니는 모든 mysql gem을 제거했습니다. 위의 내용이 작동하지 않으면 할 수 있습니다. :)


mysql을 64 비트로 다시 빌드하거나 64 비트 버전을 설치하는 것도 중요하지만 mysql gem의 기본 부분도 64 비트로 빌드해야합니다 (원래 Intel Core Duo Mac 중 하나를 사용하는 경우에는 적용되지 않음). ).

다음은 마법의 명령입니다.

env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Snow Leopard에서 기본 구성 요소로 gem을 설치할 때마다 위에 표시된대로 ARCHFLAGS를 설정해야합니다.


번 들러를 사용하는 경우 "번들 구성"을 사용하여 다음과 같이 mysql에 대한 적절한 빌드 인수를 설정할 수 있습니다.

bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

나는 이것으로 오랫동안 싸웠고 마침내 Snow Leopard에서 작동했습니다. 결국 소스에서 Ruby, RubyGems 및 MySQL 을 설치했습니다 (Ruby 및 RubyGems 설치에 대한 Hivelogic 자습서 참조 . MySQL 자습서는 하단에 링크 됨). 마침내 설치할 보석을 얻었지만 여전히

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

Trace/BPT trap

나는 마침내 mysql.bundle(나는 이것이 무엇을위한 것인지 모르겠다) 삭제했고 모두 작동했다.

sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle

누군가에게 도움이되기를 바랍니다.


나는이 문제를 여러 번 보았다. 거의 매번 컴퓨터에서 mysql을 빌드합니다. gem install 명령의 일부로 mysqlconfig를 전달해야한다고 생각합니다.

sudo gem install mysql -- --with-mysql-config=/your/mysql/config

Provided configuration options:
--with-opt-dir
--without-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=/usr/bin/ruby
--with-mysql-config

이 gem을 빌드하려면 mysql dev 파일이 필요합니다.


Snow Leopard를 설치 한 후 구성을 작동하는 데 문제가있었습니다. http://www.mamp.info 에서 MAMP를 찾았으며 Apache, PHP 및 MySQL을 번들로 제공합니다. 응용 프로그램처럼 설치하면 작동합니다. 시도해 볼 가치가 있으며 무료입니다.

망사


나는 여기서 내 질문에 답할 것이라고 생각했습니다. 문제가 mysql이 아니라 mysql 루비 바인딩에있는 것처럼 보입니다. 나는 Querius (my mysql gui)를 연결할 때 연결할 수 있었기 때문에 이것을 알아 냈습니다.

소스 수정 바인딩에서 빌드하는 방법은 다음과 같습니다.

cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install

Snow Leopard의 소스에서 빌드해야 할 라이브러리가 많이 있으며 계속 팝업됩니다. MacPorts는 모든 libs에 대해 충분히 업데이트되지 않은 것 같아서 혼자서 할 것입니다. 다음 단계 : freetype ( http://download.savannah.gnu.org/releases-noredirect/freetype/ )


이 게시물 ( http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/ ) 에서 설명한대로 진행했으며 이제 모든 것이 잘 작동합니다.

mysql 드라이버를 설치하려면 그의 명령에서 오타를 찾아야합니다.


나는 똑같은 문제가 있었고 여기에 나를 위해 일한 것이 있습니다.

  1. Snow Leopard 및 64 비트 MySQL DMG를 설치합니다.

  2. 여기에 설명 된대로 이전 MySQL 데이터 디렉토리를 가리 키도록 /etc/my.cnf를 만들고

    sudo mysql_upgrade.

  3. IRB를 열고 (blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html을 통해) 내 모든 gem을 다시 설치합니다.

    `보석 목록`.each_line {| line | 시스템 'sudo gem install # {line.split.first}'}

  4. 내가 설치 한 MySQL gem을 제거했습니다.

  5. MySQL gem을

    sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

그것으로 지금까지 모든 것이 작동하는 것 같습니다. * 노크 우드 *


MySQL을 수동으로 설치하는 대신 home brew 를 선호하는 경우 .

기존 mysql gem (있는 경우)을 제거합니다.

 sudo gem uninstall mysql 

'mysql_config'파일을 찾습니다.

 find /usr -name 'mysql_config' 

mysql gem을 다시 설치합니다.

 sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/bin/mysql_config 

Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.


Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.


I've solved it this way:

  1. after install dmg file of mysql  
  2. bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
  3. env ARCHFLAGS="-arch x86_64"
  4. bundle install

Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.

It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.

  1. Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.

  2. Install rvm:

    user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    
    user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
    
    user$ source .bash_profile
    
  3. Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.

    user$ rvm install 1.9.2
    user$ rvm use 1.9.2
    
  4. Create a gemset for the rvm ruby installed in step 2 (x is the version number).

    user$ rvm gemset create rails30x
    user$ rvm 1.9.2@rails30x
    
  5. Install Rails 3.0.x (x is the version number).

    user$  gem install rails -v 3.0.x.
    
  6. Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.

    Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:

    basedir=
    datadir=
    

    and change them to read (inserting the correct MySQL directory name):

    basedir=/usr/local/mysql-version-name
    datadir=/usr/local/mysql-version-name/data
    

    Save the file. MySQL can now be started from the preferences pane.

    To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your home folder and include the following (inserting the correct MySQL directory name):

    export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
    

    Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library would appear and the server would abort.

  7. Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).

    user$ gem install mysql2 -v 0.2.7 
    
  8. Create a rails app, and it's corresponding database (appname_development).

    user$ rails new appname
    
  9. Add this to the app's Gemfile: gem 'mysql2', "0.2.7"

  10. Add this to the app's database.yml:

    development: 
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: appname_development
      pool: 5
      username: username
      password: pwd
      host: localhost
    
  11. start app and check "About your application's environment". Everything should be working correctly.


The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:

DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

to my bash profile, and this solved it for me.


I tried the archflags trick many times with slight variations but it never worked for me.

What finally did work was switching back to the version of ruby and gem installed with snow leopard.

I had built and installed my own version which has worked for me in every respect except this one. Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.


I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql

If you are installing the mysql gem with RVM you need to use the following code to install it

sudo env ARCHFLAGS="-arch x86_64" gem install mysql

This method worked for me in Leopard Server, none of the above worked


this article solved the issue for me :)

http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html

  • Prior to Leopard

    sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

    • Leopard on a PPC machine:

      sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

    • Leopard on an Intel machine:

      sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

    • Snow Leopard (only on Intel):

      sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

참고URL : https://stackoverflow.com/questions/991708/rails-mysql-and-snow-leopard

반응형