我正在处理这几天,无法连接到本地主机上的简单 mysql 数据库。
require "mysql"
@db_host = "localhost"
@db_user = "myrubyapp"
@db_pass = "1234"
@db_name = "myrubyapp"
mysql = Mysql.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
我得到的输出是一个错误:can't convert Hash into String (TypeError)
在哪里Mysql.new
。
第二个,我尝试将gem改为mysql2
require "mysql2"
@db_host = "localhost"
@db_user = "myrubyapp"
@db_pass = "1234"
@db_name = "myrubyapp"
mysql = Mysql2.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
输出也是一个错误,但与第一个不同:undefined method "new" for Mysql2:Module (NoMethodError)
.
伙计们,很抱歉我不得不问这种问题,但我真的很困惑,我在 JavaSE 和 EE 方面有超过 3 年的编程经验,我很惭愧,因为我无法应对。请指出我正确的方向,不要严厉评判我。我是红宝石的新手。