如何在Mac OS X 10.6.6上安装mysql和ruby以及mysql / ruby

时间:2011-02-15 09:40:07

标签: mysql ruby macos osx-snow-leopard

如何在Mac OS X 10.6.6上安装mysql和ruby以及mysql / ruby​​?我收到了这个错误:

 checking for mysql_query() in -lmysqlclient... no

 ld: warning: in /usr/local/mysql/lib/libmysqlclient.dylib, 
     file was built for unsupported file format which is not the
     architecture being linked (i386)

2 个答案:

答案 0 :(得分:1)

转到http://macruby.org/downloads.html并下载并安装http://macruby.org/files/MacRuby%200.8.zip

转到http://mysql.com/downloads/mysql/并下载Mac OS X版。 10.6(x86,64位),DMG档案。

转到http://tmtm.org/en/mysql/ruby/并按照步骤下载,然后:

  1. 运行命令:ruby extconf.rb --with-mysql-config
  2. 在文本编辑器中修改文件“Makefile”并删除所有i386架构标志,即"-arch i386"
  3. 运行命令:make
  4. 运行命令:make install
  5. 运行命令:export rvm_archflags="-arch x86_64"
  6. 运行命令:export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
  7. 运行命令:ruby test.rb
  8. 运行命令:ruby ./test.rb -- [hostname [user [passwd [dbname [port [socket [flag]]]]]]]
  9. 注意:

    如果在测试时遇到类似'libmysqlclient not found'的错误,则需要指定库所在的目录,以便make可以找到它。

    % env LD_RUN_PATH=libmysqlclient.so directory make
    

    示例:

    my = Mysql.new(hostname, username, password, databasename)
    st = my.prepare("insert into tblname (col1,col2,col3) values (?,?,?)")
    st.execute("abc",123,Time.now)
    st.prepare("select col1,col2,col3 from tblname")
    st.execute
    st.fetch  # => ["abc", 123, #<Mysql::Time:2005-07-24 23:52:55>]
    st.close
    

答案 1 :(得分:0)