coreseek创建索引错误sql_fetch_row: Lost connection to MySQL server during query解决方法

发布时间:2016-03-22 17:14:35编辑:丝画阁阅读(945)

Sphinx 全文检索引擎

Sphinx 是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序更容易实 现专业化的全文检索。Sphinx特别为一些脚本语言设计搜索API接口,如PHP,Python,Perl,Ruby等,同时为MySQL也设计了一个 存储引擎插件。

本文为大家讲解的是sphinx创建索引错误sql_fetch_row: Lost connection to MySQL server during query解决方法,感兴趣的同学参考下。

错误描述

在进行索引创建的时候,出现了错误
Error: sql_fetch_row: Lost connection to MySQL server during query

完整错误如下

$ /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
Sphinx 0.9.8-rc2 (r1234)
Copyright (c) 2001-2008, Andrew Aksyonoff

using config file '/usr/local/sphinx/etc/sphinx.conf'...
indexing index 'orthodb'...
ERROR: index 'orthodb': sql_fetch_row: Lost connection to MySQL server during query.
total 2087306 docs, 18785754 bytes
total 2462.060 sec, 7630.10 bytes/sec, 847.79 docs/sec

原因分析

sphinx.conf的原有mem_limit的值是2000m, 而我在虚拟机里跑的linux系统最大也就2G, 应该是索引创建的时候的内存不足导致的, 那我们就可以设置mem_limit的值小一点。

这个mem_limit的设置是索引内存使用限制, 如果设置过大就可能导致sql链接超时, 官方文档是这么写的:

Maximum possible limit is 2047M. Too low values can hurt indexing speed, but 256M to 1024M should be enough for most if not all datasets. Setting this value too high can cause SQL server timeouts. During the document collection phase, there will be periods when the memory buffer is partially sorted and no communication with the database is performed; and the database server can timeout. You can resolve that either by raising timeouts on SQL server side or by lowering mem_limit.

另外就是searchd服务启动的用户和indexer生成索引的用户要一致, 否则也会导致查询不出结果的问题。

最后就是如果出现searchd启动出错的话, 直接查searchd的log, 很有可能是一些需要的目录未创建或者是没有权限

解决方法

修改sphinx.conf,把mem_limit改小

关键字