windows环境下,ruby 连接mysql 报错

问题描述

windows环境下,ruby 连接mysql 报错

require "D:/ruby-mysql/ruby-mysql-0.2.6/mysql"
begin
#尝试连接mysql数据库
my = Mysql.connect("localhost","root","123456","test")
#连接成功,显示Mysql数据库版本
puts my.get_server_info
rescue Mysql::Error => err
#如果失败,显示错误信息
puts "错误代码:#{err.errno}"
puts "错误信息:#{err.error}"
ensure
my.close if my
end

运行以上代码,报这样的错误:
D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:1019:in read': Packets out of order: 0<> (RuntimeError)
from D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:444:in
read'
from D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:110:in real_connect'
from D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:91:in
initialize'
from D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:1085:in new'
from D:/ruby-mysql/ruby-mysql-0.2.6/mysql.rb:1085:in
real_connect'
from D:/软件/eclipse-standard-kepler-SR2-win32/hello/testDb.rb:3:in `'

项目要用到ruby,新人,求大神帮忙,搞了一天了,没连上

解决方案

目测是你的musql端口没有指定对,或者mysql没有启动正确。或者被防火墙拦住了。

解决方案二:

参考brianmario/mysql2,你的MySQL的版本是多少?从MySQL 5.6.5开始,默认启用secure_auth

Secure auth

Starting wih MySQL 5.6.5, secure_auth is enabled by default on servers (it was disabled by default prior to this). When secure_auth is enabled, the server will refuse a connection if the account password is stored in old pre-MySQL 4.1 format. The MySQL 5.6.5 client library may also refuse to attempt a connection if provided an older format password. To bypass this restriction in the client, pass the option :secure_auth => false to Mysql2::Client.new(). If using ActiveRecord, your database.yml might look something like this:

development:
adapter: mysql2
encoding: utf8
database: my_db_name
username: root
password: my_password
host: 127.0.0.1
port: 3306
secure_auth: false

解决方案三:

不要用mysql ,用mysql2 adapter 试试.

 gem install mysql2
 require "rubygems"
require "active_record"
class Source < ActiveRecord::Base
    set_table_name "sources"
    ActiveRecord::Base.establish_connection(
        :adapter => "mysql2",
        :host => "localhost",
        :username => "test",
        :password => "test",
        :port => 3306,
        :database => "TestDB",
        :socket => "mysql"
    )
end
source = Source.find(:first, :conditions => [ "source_id = ?", 2 ])
puts source.source_name
时间: 2024-11-02 15:49:41

windows环境下,ruby 连接mysql 报错的相关文章

gem-windous环境下 rails 连接mysql 报错

问题描述 windous环境下 rails 连接mysql 报错 用railsinstaller装的环境依赖的ruby rails devkit sqlite3都装过了现在想试试mysqlC:windowssystem32>rails new E:rubykk10 -d mysql Installing mysql2 (0.3.13)Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

mingw-Code::Blocks Windows环境下编译HelloWorld程序报错,求高手支招!

问题描述 Code::Blocks Windows环境下编译HelloWorld程序报错,求高手支招! 很简单的Hello World 程序,编译时提示: D:MinGWincludec++3.4.5bitscodecvt.h|475 这个文件中引用的 bits/codecvt_specializations.h 文件找不到 请问是哪里出了问题? ?

hadoop-hive连接mysql 报错 readonly server

问题描述 hive连接mysql 报错 readonly server 各位大侠,我搭建了一个hadoop环境,用hive做数据仓库,mysql做hive的元数据仓库,用于定时分析用户数据中的日志文件,但在hive访问mysql的过程中,不定时的报如下错误: java.sql.SQLException: Query returned non-zero code: 1, cause: FAILED: Execution Error, return code 1 from org.apache.ha

远程连接-Navicat连接mysql报错!!

问题描述 Navicat连接mysql报错!! 用Navicat远程连接数据库是报错,,服务也开启了,请问什么原因 解决方案 Navicat/MySQL Front 操作 MySQL 1577 报错 解决方法 解决方案二: 是用root账号连的么.. 解决方案三: 这个问题是mysql断网下连接产生的? 解决方案四: 远程的服务器的mysql服务打开没? 解决方案五: 确定端口是否正确,有没防火墙(本机连接忽略) 解决方案六: 可能是防火墙的问题,用ping 172.16.80.62命令试下能否

PHP连接MySQL报错:SQLSTATE[HY000] [2002] Can t connect to local

如下所示,PHP连接MySQL报错: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket 'MySQL' (2) 测试代码如下: <?php try {  $dsn = 'mysql:dbname=php-note;host=localhost;port=3306;charset=utf8';  $username = 'root';  $password = 'root';  new PDO( $d

ubuntu-Ubuntu14下hadoop1.2.1环境下Hive1.1.1报错,求大神解决,谢谢

问题描述 Ubuntu14下hadoop1.2.1环境下Hive1.1.1报错,求大神解决,谢谢 Logging initialized using configuration in jar:file:/usr/local/hadoop/lib/hive-common-1.1.1.jar!/hive-log4j.properties Exception in thread "main" java.lang.UnsupportedClassVersionError: com/facebo

aix tomcat-AIX环境下启动tomcat,报错,求大神指导。

问题描述 AIX环境下启动tomcat,报错,求大神指导. 报错信息如下:./catalina.sh: /vgop/vgop/server/ng4.5/jdk1.6.0_29/jre/bin/java: 0403-006 执行许可权被拒绝.

windows下用Python连接mysql报错问题“MySQLdb in Python: “Can&#039;t connect to MySQL server on &#039;localhost&#039;””

        这几天在windows用Python连接mysql,报出了"MySQLdb in Python: "Can't connect to MySQL server on 'localhost'"", 写了一个以下的挫代码,然后出错了,各种"屌丝百科"没有果   """ __author__ = 'chenguolin' __date__=2014-02-17 """ impo

远程连接MySQL报错ERROR 2003解决办法

问题代码代码 ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.19' (111) ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.19' (111) 这个 原因就是Mysql数据库的默认配置文件my.cnf(linux下)中的bind-address默认为127.0.0.1,所以就算你创建了可以 remote访问的用户,你也不能使用mys