ruby+rails+mysql+win or linux的安装大全

来源:互联网 发布:老帅哥淘宝店 编辑:程序博客网 时间:2024/04/29 08:47

首先下载 http://rubyforge.org/frs/download.php/75468/railsinstaller-2.0.1.exe

此安装包含以下组件


安装完成之后去;git是一个程序版本控制管理工具,需要到github.com上注册一个免费用户,注册步骤如下图。

一、安装ruby-dbi
下载地址:http://rubyforge.org/projects/ruby-dbi/
下载ruby-DBI(我下载的是dbi-0.1.1.tar.gz),解压后进入目录运行如下命令:
E:\ruby-dbi>ruby setup.rb config --with=dbi,dbd_mysql
entering config phase...
config done.

E:\ruby-dbi>ruby setup.rb setup
entering setup phase...
setting #! line to "#!e:/ruby/bin/ruby"
setup.rb: skip bin/proxyserver(dbd_proxy) by user option
setup.rb: skip ext/dbd_sqlite(dbd_sqlite) by user option
setup.rb: skip ext/dbd_sybase(dbd_sybase) by user option
setup done.

E:\ruby-dbi>ruby setup.rb install
entering install phase...
mkdir -p e:/ruby/bin
install sqlsh.rb e:/ruby/bin
setup.rb: skip bin/proxyserver(dbd_proxy) by user option
mkdir -p e:/ruby/lib/ruby/site_ruby/1.8/DBD/Mysql
install Mysql.rb e:/ruby/lib/ruby/site_ruby/1.8/DBD/Mysql/Mysql.rb
mkdir -p e:/ruby/lib/ruby/site_ruby/1.8/dbi
install columninfo.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install row.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install sql.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install trace.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install utils.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install version.rb e:/ruby/lib/ruby/site_ruby/1.8/dbi
install dbi.rb e:/ruby/lib/ruby/site_ruby/1.8
setup.rb: skip ext/dbd_sqlite(dbd_sqlite) by user option
setup.rb: skip ext/dbd_sybase(dbd_sybase) by user option
install done.

二、安装MySQL/Ruby for Windows
下载地址:http://www.vandomburg.net/pages/mysql-ruby-windows
我的文件为:mysql-ruby-windows-2.7.3-r1.zip
安装方法(我直接把英文的步骤拷贝过来吧,这个我测试过,没问题):
1、Select and copy the .so file of your choice to %RUBYARCHDIR% and rename it to mysql.so (e.g. C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\mysql.so).

The 4.1 and 5.0 directories correspond to your MySQL server version. (For all you tech savvies: they are generally interchangable, but differ slightly on byte level in terms of argument types.)

The ‘vanilla’ library is the stock MySQL/Ruby 2.7.3 we all know and love. The ‘performance’ library has Stefan Kaes’ garbage correction patch applied that can increase performance anywhere from 5% to 30% depending on the size of the data set you’re accessing. The flip-side is this: it is less tested, so take your pick!

2、MySQL/Ruby needs a DLL dependency satisfied in order to run. You can do this by either:

(Recommended) Including the MySQL bindir in your path (e.g. C:\Program Files\MySQL\MySQL Server 5.0\bin).

3、Copying libmySQL.dll from your MySQL bindir or source package to your Ruby bindir (e.g. C:\ruby\bin).

To verify, try to run the following code:

require 'mysql'
puts Mysql::VERSION

If it outputs 20703, then you’re all set up! Just be sure that you’re MySQL server has TCP/IP connections enabled.

三、Linux 上的安装方法:
1、对于ruby-dbi没有什么区别,此略。
2、MySQL/Ruby for Linux
下载地址:http://tmtm.org/downloads/mysql/ruby/
我下载的文件:mysql-ruby-2.7.1.tar.gz
安装方法(因为比较懒惰,也弄一段英文的安装步骤在此吧):
The module is distributed as a compressed tar file, which you should unpack after downloading it. For example, if the current version is 2.7.1, the distribution file can be unpacked using either of the following commands:

% tar zxf mysql-ruby-2.7.1.tar.gz
% gunzip < mysql-ruby-2.7.1.tar.gz | tar xf -

After unpacking the distribution, change location into its top-level directory and configure it using the extconf.rb script in that directory:

% ruby extconf.rb

If extconf.rb successfully locates your MySQL header file and library directories, you can proceed to build and install the module. Otherwise, it indicates what it could not find, and you'll need to run the command again with additional options that specify the appropriate directory locations. For example, if your header file and library directories are /usr/local/mysql/include/mysql and /usr/local/mysql/include/lib, the configuration command looks like this:

% ruby extconf.rb \
--with-mysql-include=/usr/local/mysql/include/mysql \
--with-mysql-lib=/usr/local/mysql/lib/mysql

Alternatively, tell extconf.rb where to find the mysql_config program. In that case, extconf.rb runs mysql_config to locate the header and library files:

% ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config

After configuring the distribution, build and install the module:

% make
% make install

You might need to run the installation command as root.

安装rails,命令行键入: gem install rails

配置ruby下的mysql连接

6.1 把Mysql安装目录中bin目录下的libmysql.dll 复制到ruby安装目录的bin目录下(一般是c:\ruby\bin下)

6.2 到http://rubyforge.org/frs/?group_id=627 下载rdoc-2.4.3.gem (注意:只能用迅雷下,直接另存为后,文件后缀名将变成非.gem的东东),然后把rdoc-2.4.3.gem复制到c:\ruby\down下(down目录是我自己建的),然后命令行:

cd c:\ruby\down

gem install rdoc-2.4.3.gem

6.3 安装mysql for ruby的驱动,命令行键入: gem install mysql

6.4 把mysql.so复制到C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt下(mysql.so文件如果本机找不到,可在http://rubyforge.org/frs/?group_id=904 下载InstantRails-2.0-win.zip解压后得到)(非必要)

然后就可以在代码中连接了:





以下时出现  library 客户端版本号不匹配错误的解决方法


从mysql官方http://dev.mysql.com/downloads/mysql下载 mysql-connector-c-noinstall-6.0.2-win32 

解压到e:/。注意根据自己的实际情况下载相对应的版本,这里使用非安装版。

or Ruby 1.9.2:

gem install mysql --platform=ruby -- --with-mysql-dir=e:/mysql-connector-c-noinstall-6.0.2-win32

for Ruby 1.9.3: (showing mysql2 variant)

gem pristine mysql2 -- --with-mysql-config=e:\mysql-connector-c-noinstall-6.0.2-win32 

这里我用64位的win7系统.

然后将 E:\mysql-connector-c-noinstall-6.0.2-win32\lib 目录下的 libmysql.lib 文件复制到 E:\RailsInstaller\Ruby1.9.3\bin 目录下。

重新执行刚才的命令即可。



原创粉丝点击