Lost connection to MySQL server at 'reading initial communication packet', system error: 0

1,780 views
Skip to first unread message

J. Garcia

unread,
Jul 11, 2013, 1:28:27 PM7/11/13
to thinkin...@googlegroups.com
I'm having a hard time trying to set up a working thinking-sphinx configuration.

My setup:
  • Win 7
  • Rails: 3.2.13
  • MySql: 5.5.32
  • Ruby:1.9.3
  • Sphinx:2.0.8
  • thinking_sphinx:3.0.4
  • mysql2: 0.3.12b5
I must say there was hardly no info on how to get started with thinking_sphinx.
After adding the gem, and googling a lot, I added a config/thinking_sphinx.yml and put this onto it:

development:
  host: localhost
  port: 9306
  bin_path: F:\sw\sphinx-2.0.8-release-win32\bin
  searchd_binary_name: searchd
  indexer_binary_name: indexer

Notice it says port, and not mysql41 as it is explained in thinking_sphinx.

The app/indices part was documented well and I created this folder and added a model_index.rb file as explained.

After this, I run:
rake ts:index

and if successfully indexed my model entities and created a development.sphinx.conf file:

Generating configuration to E:/home/my_project/config/development.sphinx.conf
Sphinx 2.0.8-release (r3831)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'E:/home/my_project/rails/music_collect/config/development.sphinx.conf'...
WARNING: key 'address' is deprecated in E:/home/my_project/config/development.sphinx.conf line 7; use 'listen' instead.
indexing index 'mymodel_core'...
collected 1000 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1000 docs, 17768 bytes
total 0.037 sec, 470003 bytes/sec, 26452.22 docs/sec
total 2 reads, 0.000 sec, 21.4 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 11.5 kb/call avg, 0.0 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=7456).

However, when I call MyModel.search in my controller, I get this error:

Mysql2::Error at /mymodels

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

It works fine if I do a MyModel.all , which directly talks to MySql backend.

Any help would be appreciated.

Pat Allan

unread,
Jul 11, 2013, 7:08:28 PM7/11/13
to thinkin...@googlegroups.com
You shouldn't need to manually set a port to get things started - but if you are, you must use mysql41 with the 3.x releases of Thinking Sphinx, *not* port.

So:

development:
mysql41: 9306 # this is the default anyway!


bin_path: F:\sw\sphinx-2.0.8-release-win32\bin

You were using the default binary names and host, so there's no need to set them.

Also: you need to run the ts:start rake task to get the Sphinx daemon running.

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphi...@googlegroups.com.
> To post to this group, send email to thinkin...@googlegroups.com.
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


J. Garcia

unread,
Jul 12, 2013, 7:28:06 AM7/12/13
to thinkin...@googlegroups.com
Thanks Pat for your reply.

I do run ts:start:
> rake ts:start
Started searchd successfully (pid: 4044).

Then, when doing a search, this is what I get in my Rails app:

Lost connection to MySQL server at 'reading initial communication packet', system error: 0
The partial stacktrace is:
Mysql2::Error - Lost connection to MySQL server at 'reading initial communication packet', system error: 0:
  mysql2 (0.3.12b5) lib/mysql2/client.rb:56:in `connect'
  mysql2 (0.3.12b5) lib/mysql2/client.rb:56:in `initialize'
  thinking-sphinx (3.0.4) lib/thinking_sphinx/connection.rb:59:in `new'
  thinking-sphinx (3.0.4) lib/thinking_sphinx/connection.rb:59:in `initialize'
  thinking-sphinx (3.0.4) lib/thinking_sphinx/connection.rb:14:in `new'
  thinking-sphinx (3.0.4) lib/thinking_sphinx/connection.rb:14:in `new'
  thinking-sphinx (3.0.4) lib/thinking_sphinx/connection.rb:26:in `block in pool'
  innertube (1.0.2) lib/innertube.rb:120:in `call'
  innertube (1.0.2) lib/innertube.rb:120:in `block in take'

If I change the port param to mysql41: 9306 nothing changes.
It's frustrating, as the examples look really good and I was trying it out...

A minor pain is when I run rake ts:stop it never ends. Then I cancel the command and manually kill the searchd process.

J. Garcia

Pat Allan

unread,
Jul 12, 2013, 7:33:09 AM7/12/13
to thinkin...@googlegroups.com
Once you've changed the port setting to mysql41, have you run rake ts:index (which will regenerate the configuration file)?

J. Garcia

unread,
Jul 12, 2013, 8:55:07 AM7/12/13
to thinkin...@googlegroups.com
With mysql41: 9306 in thinking_sphinx.yml:

> rake ts:index --trace
** Invoke ts:index (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute ts:index
Generating configuration to E:/home/myproject/config/development.sphinx.conf
rake aborted!
Riddle::Configuration::ConfigurationError
C:/Ruby193/lib/ruby/gems/1.9.1/gems/riddle-1.5.7/lib/riddle/configuration/searchd.rb:24:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/riddle-1.5.7/lib/riddle/configuration.rb:37:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/thinking-sphinx-3.0.4/lib/thinking_sphinx/configuration.rb:84:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/thinking-sphinx-3.0.4/lib/thinking_sphinx/configuration.rb:90:in `block in render_to_file'
C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:35:in `open'
C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:35:in `open'
...

If I just delete the 9306 line, the same error.

If I revert it back to port: 9306, it works well:

E:\home\elektrik\proyectos\rails\music_collect>rake ts:index --trace
** Invoke ts:index (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute ts:index
Generating configuration to E:/home/myproject/config/development.sphinx.conf
Sphinx 2.0.8-release (r3831)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'E:/home/myproject/config/development.sphinx.conf'...
WARNING: key 'address' is deprecated in E:/home/myproject/config/development.sphinx.conf line 7; use 'listen' instead.
indexing index 'brand_core'...
collected 1000 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 1000 docs, 17768 bytes
total 0.093 sec, 189041 bytes/sec, 10639.42 docs/sec
total 2 reads, 0.000 sec, 21.4 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.001 sec, 11.5 kb/call avg, 0.1 msec/call avg

Also, the ts:start produces this log in development.searchd.log file:

[Fri Jul 12 14:50:18.387 2013] [ 2768] listening on 127.0.0.1:9306
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: replaying log E:/home/elektrik/proyectos/rails/music_collect/tmp/binlog/development/binlog.001
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: replay stats: 0 rows in 0 commits; 0 updates; 0 indexes
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: finished replaying E:/home/myproject/tmp/binlog/development/binlog.001; 0.0 MB in 0.000 sec
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: replaying log E:/home/myproject/tmp/binlog/development/binlog.002
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: replay stats: 0 rows in 0 commits; 0 updates; 0 indexes
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: finished replaying E:/home/myproject/tmp/binlog/development/binlog.002; 0.0 MB in 0.000 sec
[Fri Jul 12 14:50:18.391 2013] [ 2768] binlog: replaying log E:/home/myproject/tmp/binlog/development/binlog.003
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: replay stats: 0 rows in 0 commits; 0 updates; 0 indexes
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: finished replaying E:/home/myproject/tmp/binlog/development/binlog.003; 0.0 MB in 0.000 sec
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: replaying log E:/home/myproject/tmp/binlog/development/binlog.004
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: replay stats: 0 rows in 0 commits; 0 updates; 0 indexes
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: finished replaying E:/home/myproject/tmp/binlog/development/binlog.004; 0.0 MB in 0.000 sec
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: replaying log E:/home/myproject/tmp/binlog/development/binlog.005
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: replay stats: 0 rows in 0 commits; 0 updates; 0 indexes
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: finished replaying E:/home/myproject/tmp/binlog/development/binlog.005; 0.0 MB in 0.000 sec
[Fri Jul 12 14:50:18.392 2013] [ 2768] binlog: finished replaying total 5 in 0.001 sec
[Fri Jul 12 14:50:18.394 2013] [ 2768] accepting connections

On Thursday, July 11, 2013 7:28:27 PM UTC+2, J. Garcia wrote:

Pat Allan

unread,
Jul 12, 2013, 9:38:38 PM7/12/13
to thinkin...@googlegroups.com
I'm not quite sure how to set environment variables, but I'm wondering if this is related to the Riddle gem failing to detect which version of Sphinx you've got installed. If you can set the SPHINX_VERSION environment variable to 2.0.8, that could help.

You'll definitely need to use mysql41 instead of port - my guess of the original error is that it's using the old binary Sphinx protocol on 9306 instead of the mysql41 protocol, which is why Sphinx is active on 9306 but expecting different sets of bytes.

--
Pat

J. Garcia

unread,
Sep 10, 2013, 4:40:50 AM9/10/13
to thinkin...@googlegroups.com
Setting SPHINX_VERSION as system-wide environment variable worked. Perhaps it should be mentioned in the README.

Thanks.
J.


You received this message because you are subscribed to a topic in the Google Groups "Thinking Sphinx" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/a8Pww2WnDbg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thinking-sphi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages