tmtm / ruby-mysql

MySQL connector for Ruby. pure Ruby version.
MIT License
143 stars 34 forks source link

Invalid packet: sequence number mismatch #8

Closed markfrommer closed 12 years ago

markfrommer commented 13 years ago

Sorry, I accidentally closed my issue. I am getting this error sometimes, but not on every query. The error seems to occur when the result includes more data; shorter results are OK. I am using MySQL 5.5.8, ruby-mysql 2.9.4. OS-X 10.6.5. Error message follows:

Mysql::ProtocolError: invalid packet: sequence number mismatch(32 != 11(expected)): SELECT * FROM templates WHERE (templates.site_id = 50)

markfrommer commented 13 years ago

Further developments on this issue: I deleted the line referred to in the other "invalid packet" issue to the source code of ruby-mysql 2.9.3, and that version now seems to be working without any problems on the same code that raised the error above when using 2.9.4.

DiogoAndre commented 13 years ago

Exactlly same thing happening here, same code runs fine with 2.9.3. One query that triggers the error is:

SELECT boat_classes.* FROM boat_classes WHERE boat_classes.class_type IS NULL ORDER BY name

Genkilabs commented 13 years ago

Similar error on 2.9.4 for a really ordinary query. ActiveRecord::StatementInvalid (Mysql::ProtocolError: invalid packet: sequence number mismatch(32 != 145(expected)): SELECT 'deliveries'.* FROM 'deliveries' WHERE ('deliveries'.warehouse_id = 4) ORDER BY date DESC):

The query, SELECT deliveries.* FROM deliveries WHERE (deliveries.warehouse_id = 4) ORDER BY date DESC

is from @warehouse.deliveries.all.paginate(:page => params[:page], :per_page => 10)

where Warehouse has_many :deliveries. It's a pretty normal line that occurs similarly for other models, but I can't identify why this particular one breaks... Moving back to 2.9.3 fixes the issue completely. Quick fix => gem 'ruby-mysql', '2.9.3'

tycoool commented 13 years ago

I had the same problem but moving back to 2.9.3 didn't fix the issue completely. I run in the "invalid packet" issue of version 2.9.3. The workaround is implicit in first comment (markfrommer, January 21, 2011) but I prefer to make it explicit here, since it took me a while to figure out.

1) Move back to 2.9.3. 2) if you run in the "invalid packet" issue (https://github.com/tmtm/ruby-mysql/issues/6) of version 2.9.3, fix it as described here (https://github.com/tmtm/ruby-mysql/commit/07ddfafafbd1d46bbb71c7cb54ae0f03bc998d27)

rtacconi commented 13 years ago

I switched back to 2.9.3 and I get: Mysql::ProtocolError

invalid packet: f1="\017\200\025\000\000\000\000\000\000\000\000\000\000"

Rails.root: /opt/local/apache2/rails-data/apps Application Trace | Framework Trace | Full Trace

ruby-mysql (2.9.2) lib/mysql/protocol.rb:666:in parse' ruby-mysql (2.9.2) lib/mysql/protocol.rb:238:inauthenticate' ruby-mysql (2.9.2) lib/mysql.rb:111:in `real_connect'

With mysql and mysql2 gems is ok (but the are not loading under passenger, rvm and Mac)

markfrommer commented 13 years ago

rtacconi- you have to fix the 2.9.3 code according to the link in the comment right before yours. Then it will work.

vladgurovich commented 13 years ago

Im still getting this error on OSX with 2.9.3 after applying the above fixes (which are by the way not for "sequence number mismatch" but for "f1=XXXXX" error ) The error is as follows: ActiveRecord::StatementInvalid (Mysql::ProtocolError: invalid packet: sequence number mismatch(90 != 9(expected)): SELECT sessions.* FROM sessions WHERE (sessions.session_id = 'f4132425a61d71a736cedffc89f59d14') LIMIT 1):

The exception is raised at https://github.com/tmtm/ruby-mysql/blob/07ddfafafbd1d46bbb71c7cb54ae0f03bc998d27/lib/mysql/protocol.rb#L569 Do you know if removing this line is appropriate?

rtacconi commented 13 years ago

you just need to comment that line (569). Make sure you are editing the gem you are using in your program, if you are using bundle try:

bundle show ruby-mysql

vladgurovich commented 13 years ago

Right, my concern is that this hides the symptom, not fixes the problem. I mean this raise error line is there for some reason? Furthermore is it possible to only remove it on OSX platforms using some sort of architecture check?

ened commented 13 years ago

Also seems to happen on CentOS sometimes.

WilliamDenniss commented 13 years ago

I was getting a Mysql::ProtocolError as well, in Mac OS X 10.6, with both 2.9.3 and 2.9.4 versions of ruby-mysql, but only with a particular version of MySQL. Removing that line of code fixed the issue.

Here is the output from mysqld --version:

On the machine running an older 32 bit version of MySQL – no problems with 2.9.3 or 2.9.4) /usr/local/mysql/bin/mysqld Ver 5.1.48 for apple-darwin10.3.0 on i386 (MySQL Community Server (GPL))

On the machine running the latest 64 bit version of MySQL – downgraded to 2.9.3 and removed the line of code above to get working /usr/local/mysql/bin/mysqld Ver 5.5.12 for osx10.6 on i386 (MySQL Community Server (GPL))

MarioRuiz commented 13 years ago

Not working in my case, still getting the message on 2.9.4: C:/Ruby187/lib/ruby/gems/1.8/gems/ruby-mysql-2.9.4/lib/mysql/protocol.rb:569:in `read': invalid packet: sequence number mismatch(3 != 1(expected)) (Mysql::ProtocolError)

If I remove the line 569 in protocol.rb then I get this message: C:/Ruby187/lib/ruby/gems/1.8/gems/ruby-mysql-2.9.4/lib/mysql/protocol.rb:589:in `read': Bad handshake (Mysql::ServerError::HandshakeError)

If I downgrade, the same problem

markfrommer commented 13 years ago

The line to comment out or remove is 666, in protocol.rb

MarioRuiz commented 13 years ago

when commenting the line 666 on 2.9.3: C:/Ruby187/lib/ruby/gems/1.8/gems/ruby-mysql-2.9.3/lib/mysql/protocol.rb:569:in `read': invalid packet: sequence number mismatch(3 != 1(expected)) (Mysql::ProtocolError)

markfrommer commented 13 years ago

Well, I don't know then. What version of MySQL are you using? What OS?

MarioRuiz commented 13 years ago

where I'm running ruby: Windows 7 32bits and the only thing I have install in here related to mysql is the ruby-mysql gem. The server with MySQL db I don't know the OS or MySQL version.

markfrommer commented 13 years ago

I have never succeeded in getting the ruby-mysql gem to work with a remote database. I'm strictly using it with localhost databases. The original mysql gem does work with remote databases in some cases, but doesn't seem to work at all with recent versions of mysql. If the mysql is 5.0, the original mysql gem may work. I suggest you try that first. Another scheme that might work is to connect to a local instance of mysql with a federated database to the remote.

SJD commented 12 years ago

Apply this patch to your ruby-mysql. If you see the 'old style password not supported' message, then you will need to rehash the db password you are using.

https://github.com/tmtm/ruby-mysql/commit/11ae468f81c465b45340

tmtm commented 12 years ago

I fixed this problem. Please use ruby-mysql 2.9.5.

markfrommer commented 12 years ago

Thanks for the notice. I will start using that version.

On Apr 16, 2012, at 10:54 AM, TOMITA Masahiro wrote:

I fixed this problem. Please use ruby-mysql 2.9.5.


Reply to this email directly or view it on GitHub: https://github.com/tmtm/ruby-mysql/issues/8#issuecomment-5155520

xionglingfeng commented 8 years ago

I still hit this bug at FreeBSD. I tried from version 2.9.3 to 2.9.14, all of them have the same problem

:err=>#<Mysql::ProtocolError: invalid packet: sequence number mismatch(107 != 4(expected))>

But in Mac OS X, version 2.9.14 works perfectly. Maybe it is platform-dependent?