我安装的rails1.9.3默认是mysql2数据库,这个性能究竟比mysql强在哪里,没研究过,也不太会用,看网上有说在windows环境下性能体现不出来,所以还是想用mysql数据库连接,步骤如下:
  1.首先卸载掉mysql2:
  gemuninstallmysql2
  2.安装mysqlruby驱动,需要指定参数,否则以后启动会报错:
  geminstallmysql--platform=ruby--'--with-mysql-lib="[mysql安装路径]lib"--with-mysql-include="[mysql安装路径]include"--with-mysql-dir="[mysql安装路径]"'
  3.修改database.yml文件:
  adapter:mysql2改为:mysql
  4.修改项目的gemfile:
  注释掉下面一行:
  #gemmysql2
  改为:
  gemmysql
  5.用下面的程序测试mysql数据库链接,需在mysql中先见一个railsTest的database,然后run下面的测试脚本:
MySqlTest.rb:
classMysqlTest
#Codehere
require"mysql"
deftestMysql
dbc=Mysql.real_connect('localhost','root','fm0vrwc','mysql')
res=dbc.query('select*fromuser')
puts"TestMysql...."
whilerow=res.fetch_rowdo
puts"#{row[0]}"
end
end
defcreateTable
dbc=Mysql.real_connect('localhost','root','fm0vrwc','railsTest')
dbc.query("droptableifexistsusers")
dbc.query("createtableusers(idint,namechar(20),ageint)")
dbc.query("insertintousersvalues(1,'Tom',30)")
dbc.query("insertintousersvalues(2,'Art',50)")
dbc.query("insertintousersvalues(3,'Kevin',40)")
printf"CreateTable........"
printf"%drowswereinserted ",dbc.affected_rows
res=dbc.query("SELECT*FROMusers")
puts"===SelectData=== "
whilerow=res.fetch_rowdo
printf"%d,%s,%d ",row[0],row[1],row[2]
end
puts"================== "
puts"Serverversion:"+dbc.get_server_info
rescueMysql::Error=>e
puts"Errorcode:#{e.errno}"
puts"Errormessage:#{e.error}"
puts"ErrorSQLSTATE:#{e.sqlstate}"ife.respond_to?("sqlstate")
ensure
puts"CloseConnection......."
dbc.closeifdbc
end
(MysqlTest.new).testMysql
(MysqlTest.new).createTable
end