title: Cannot connect to mysql via sphinx-specific port
body: <p>I am trying to set up sphinx search engine on the server.</p>
  
  <p>On the server already is another sphinx search daemon, that running from another user for another site with another config file (port 3312).</p>
  
  <p>Here is my sphinx config file <strong>/opt/sphinx/etc/site-sphinx.conf</strong></p>
  
  <pre><code>source site_source
  {
      type        = mysql
      sql_host    = localhost
      sql_user    = username
      sql_pass    = password
      sql_db      = dbname
      sql_port    = 3306
      sql_sock    = /var/run/mysqld/mysqld.sock
  
      mysql_connect_flags = 32
  
      sql_query_pre       = SET NAMES utf8
      sql_query_pre       = SET SESSION query_cache_type=ON
  
      sql_query = SELECT id, title, description, is_deleted, created_at, updated_at FROM table WHERE is_deleted = 0
  
      sql_attr_bool       = is_deleted
      sql_attr_timestamp  = created_at
      sql_attr_timestamp  = updated_at
  
      sql_ranged_throttle = 0
  }
  
  index sitename
  {
      type                = plain
      source              = site_source
  
      path                = /opt/sphinx/var/data/site_index/site
      docinfo             = extern
      dict                = keywords
      mlock               = 0
      morphology          = stem_en, stem_ru, soundex, metaphone
  
      enable_star         = 1
      min_stemming_len    = 1
      min_word_len        = 1
      min_infix_len       = 3
  
      html_strip          = 1
      html_remove_elements    = style, script
  }
  
  indexer
  {
      mem_limit                   = 1024M
  }
  
  searchd
  {
      listen                  = 127.0.0.1:3313
      log                     = /opt/sphinx/var/log/site/search.log
      query_log               = /opt/sphinx/var/log/site/query.log
      binlog_path             = /opt/sphinx/var/data/site_binlog
  
      read_timeout            = 5
      max_children            = 30
      pid_file                = /opt/sphinx/var/run/searchd-site.pid
  }
  </code></pre>
  
  <p>I got to start <strong>sphinxd</strong></p>
  
  <pre><code>site@servername:~$ /opt/sphinx/bin/searchd --config /opt/sphinx/etc/site-sphinx.conf
  Sphinx 2.2.9-id64-release (rel22-r5006)
  Copyright (c) 2001-2015, Andrew Aksyonoff
  Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
  
  using config file '/opt/sphinx/etc/site-sphinx.conf'...
  WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
  listening on 127.0.0.1:3313
  precaching index 'site'
  precached 1 indexes in 0.051 sec
  
  
  shapoval@sitename$ netstat -nlp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp        0      0 127.0.0.1:3313          0.0.0.0:*               LISTEN      21225/searchd
  tcp        0      0 127.0.0.1:3312          0.0.0.0:*               LISTEN      26694/searchd
  tcp6       0      0 :::3306                 :::*                    LISTEN      16998/mysqld
  </code></pre>
  
  <p>And I got to start indexing</p>
  
  <pre><code>site@servername:~$ /opt/sphinx/bin/indexer --all --rotate --config /opt/sphinx/etc/site-sphinx.conf delta
  using config file '/opt/sphinx/etc/site-sphinx.conf'...
  WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
  indexing index 'site'...
  WARNING: index 'site': dict=keywords and prefixes and morphology enabled, forcing index_exact_words=1
  collected 1660326 docs, 674.2 MB
  sorted 231.9 Mhits, 100.0% done
  total 1660326 docs, 674237370 bytes
  total 155.531 sec, 4335045 bytes/sec, 10675.15 docs/sec
  total 16 reads, 15.074 sec, 61858.4 kb/call avg, 942.1 msec/call avg
  total 1950 writes, 1.040 sec, 998.5 kb/call avg, 0.5 msec/call avg
  rotating indices: successfully sent SIGHUP to searchd (pid=25377).
  </code></pre>
  
  <p>But I can not connect to the database, either from the command line or from php (I use yii2, for connection to sphinx use yii2-sphinx).</p>
  
  <p>When I try to connect to mysql from the command line, an error occurs:</p>
  
  <pre><code>shapoval@servername$ mysql -h0 -P3313 -u username -p
  Enter password: 
  ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"
  </code></pre>
  
  <p>When I try to run a query from the site occurs several errors:</p>
  
  <pre><code>2015-12-22 10:03:08 [10.10.10.10][][-][error][yii\db\Exception] exception 'yii\base\ErrorException' with message 'Packets out of order. Expected 0 received 1. Packet size=0' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:558
  Stack trace:
  #0 /var/www/sitename/common/extensions/rollbar/RollbarErrorHandlerTrait.php(35): yii\base\ErrorHandler-&gt;handleError(2, 'Packets out of ...', '/var/www/sitename...', 558)
  #1 [internal function]: common\extensions\rollbar\RollbarErrorHandler-&gt;handleError(2, 'Packets out of ...', '/var/www/sitename...', 558, Array)
  #2 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(558): PDO-&gt;__construct('mysql:host=127....', 'username', 'password', NULL)
  #3 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(508): yii\db\Connection-&gt;createPdoInstance()
  #4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection-&gt;open()
  #5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection-&gt;createCommand('SHOW TABLES')
  #6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema-&gt;findIndexes()
  #7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema-&gt;initIndexesInfo()
  #8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema-&gt;getIndexTypes()
  #9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema-&gt;resolveIndexType(Object(yii\sphinx\IndexSchema))
  #10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema-&gt;loadIndexSchema('sitename')
  #11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema-&gt;getIndexSchema('sitename', false)
  #12 /var/www/sitename/html/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection-&gt;getIndexSchema('sitename')
  #13 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder-&gt;buildWhere(Array, 'MATCH(:qp0)', Array)
  #14 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder-&gt;build(Object(yii\sphinx\Query))
  #15 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query-&gt;createCommand(NULL)
  #16 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query-&gt;all()
  #17 [internal function]: common\actions\SphinxSearchAction-&gt;run()
  #18 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
  #19 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action-&gt;runWithParams(Array)
  #20 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller-&gt;runAction('search', Array)
  #21 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module-&gt;runAction('site/search', Array)
  #22 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application-&gt;handleRequest(Object(yii\web\Request))
  #23 /var/www/sitename/frontend/web/index.php(18): yii\base\Application-&gt;run()
  #24 {main}
  
  Next exception 'PDOException' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:558
  Stack trace:
  #0 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(0): PDO-&gt;__construct()
  #1 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(508): yii\db\Connection-&gt;createPdoInstance()
  #2 /var/www/sitename/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection-&gt;open()
  #3 /var/www/sitename/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection-&gt;createCommand('SHOW TABLES')
  #4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema-&gt;findIndexes()
  #5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema-&gt;initIndexesInfo()
  #6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema-&gt;getIndexTypes()
  #7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema-&gt;resolveIndexType(Object(yii\sphinx\IndexSchema))
  #8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema-&gt;loadIndexSchema('sitename')
  #9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema-&gt;getIndexSchema('sitename', false)
  #10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection-&gt;getIndexSchema('sitename')
  #11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder-&gt;buildWhere(Array, 'MATCH(:qp0)', Array)
  #12 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder-&gt;build(Object(yii\sphinx\Query))
  #13 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query-&gt;createCommand(NULL)
  #14 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query-&gt;all()
  #15 [internal function]: common\actions\SphinxSearchAction-&gt;run()
  #16 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
  #17 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action-&gt;runWithParams(Array)
  #18 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller-&gt;runAction('search', Array)
  #19 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module-&gt;runAction('site/search', Array)
  #20 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application-&gt;handleRequest(Object(yii\web\Request))
  #21 /var/www/sitename/frontend/web/index.php(18): yii\base\Application-&gt;run()
  #22 {main}
  
  Next exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:513
  Stack trace:
  #0 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection-&gt;open()
  #1 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection-&gt;createCommand('SHOW TABLES')
  #2 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema-&gt;findIndexes()
  #3 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema-&gt;initIndexesInfo()
  #4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema-&gt;getIndexTypes()
  #5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema-&gt;resolveIndexType(Object(yii\sphinx\IndexSchema))
  #6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema-&gt;loadIndexSchema('sitename')
  #7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema-&gt;getIndexSchema('sitename', false)
  #8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection-&gt;getIndexSchema('sitename')
  #9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder-&gt;buildWhere(Array, 'MATCH(:qp0)', Array)
  #10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder-&gt;build(Object(yii\sphinx\Query))
  #11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query-&gt;createCommand(NULL)
  #12 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query-&gt;all()
  #13 [internal function]: common\actions\SphinxSearchAction-&gt;run()
  #14 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
  #15 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action-&gt;runWithParams(Array)
  #16 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller-&gt;runAction('search', Array)
  #17 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module-&gt;runAction('site/search', Array)
  #18 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application-&gt;handleRequest(Object(yii\web\Request))
  #19 /var/www/sitename/frontend/web/index.php(18): yii\base\Application-&gt;run()
  #20 {main}
  </code></pre>
  
  <p>Sphinx connection settings in yii2</p>
  
  <pre><code>&lt;?php
  return [
      'dsn' =&gt; 'mysql:host=127.0.0.1;port=3313;',
      'username' =&gt; 'username',
      'password' =&gt; 'password',
  ];
  </code></pre>
  
  <p>The code in yii2 to execute the query</p>
  
  <pre><code>$query = (new Query())
          -&gt;from('sourceName')
          -&gt;match('*'.Yii::$app-&gt;request-&gt;get('q').'*');
  $rows = $query-&gt;all();
  </code></pre>
  
  <p>Additional server information:</p>
  
  <ul>
  <li>Ubuntu 15.04</li>
  <li>Linux 3.19.0-21-generic x86_64</li>
  <li>Sphinx 2.2.9-id64-release (rel22-r5006)</li>
  <li>MySQL 10.0.20-MariaDB-1~vivid-log</li>
  </ul>
  
  <p>What could be the problem?</p>
  
  <p>I would be glad of any assistance. Thanks!</p>