ivinco
Minimal Sphinx configuration to play with Sphinx

Minimal Sphinx configuration to play with Sphinx

Sergey NikolaevSergey Nikolaev··Updated

If you want to start learning Sphinx or see how some its feature works the following simplest Sphinx configuration might be useful:

source min
{
    type = mysql
    sql_host = localhost
    sql_user = root
    sql_pass =
    sql_db = test
    sql_query = select 1, 'cat' union select 2, 'dog'
}

index idx_min
{
    path = idx
    source = min
}

searchd
{
    listen = 9306:mysql41
    log = sphinx.log
    pid_file = sphinx.pid
    binlog_path =
}

It contains almost nothing, but only those things Sphinx cannot work without. Those are:

  • Section "source" to fetch data from mysql. In this case we don't even fetch real data from mysql, but just use mysql interface having the data defined right in the config ("select 1, 'cat' union select 2, 'dog'"). It will create 2 documents in Sphinx: one containing word "cat", another one with word "dog", the ids are 1 and 2 respectively.

  • Section "index" to create index based on the above source, it contains only reference to the source ("source = min") and path to the index ("path = idx"). Once you build this index files idx.* will be created in the dir you start 'indexer' from.

  • Section "searchd" to tell Sphinx what ports it should be listening ("listen = 9307:mysql41" which means that SphinxQL should be used to talk to Sphinx on this port), what log it should use ("log = sphinx.log") and where it should save its process id ("pid_file = sphinx.pid")

Here's an example of using this config:

  • Indexing:

  • Using 'search' tool to find some results:

  • Starting 'searchd' and fetching results using mysql client:

Enjoy playing with Sphinx!


Need help with search infrastructure? See how Ivinco's development team can help →

Frequently Asked Questions

What is the minimum Sphinx configuration needed to get started?

A minimal Sphinx config requires three sections: a source (defining where data comes from), an index (defining where to store it), and a searchd section (defining the listening port and log paths). You can skip fetching real database data by inlining test data directly in sql_query with a UNION SELECT — two documents are enough to test indexing and searching.

How do you test Sphinx search queries locally?

After building your index with the indexer command, start searchd and connect via any MySQL client on the configured port (e.g., 9306). Run SphinxQL queries like SELECT * FROM idx_min WHERE MATCH('cat') to verify results. This approach works identically whether you're running Sphinx locally or on a remote server.

What is SphinxQL and how does it differ from the Sphinx API?

SphinxQL is a SQL-like interface for querying Sphinx, accessible through any MySQL client on the port configured with listen = 9306:mysql41. It replaced the older Sphinx API for most use cases because it supports standard SQL tools, is easier to debug, and works with connection pooling.