T
T
ta42015-11-09 17:03:29
Sphinx
ta4, 2015-11-09 17:03:29

How to fix "No database selected" error in Sphinx and Yii2?

There is a sphinx.conf config:

source base_source
{
  type = mysql
  sql_host = 127.0.0.1
  sql_user = asdasd
  sql_pass = asd
  sql_db = db_bayboow
  sql_port = 3306 # optional, default is 3306
}

.
.
.
searchd {
  listen                        = 9312
  listen                        = 9306:mysql41
  log = /var/log/sphinxsearch/searchd.log
  query_log = /var/log/sphinxsearch/query.log
  pid_file = /var/log/sphinxsearch/searchd.pid
  read_timeout = 5
  max_children = 30
  max_matches = 1000
  seamless_rotate = 1
  preopen_indexes = 0
  unlink_old = 1
}

Connected component in Yii2 config:
'sphinx' => [
            'class' => 'yii\sphinx\Connection',
            'dsn' => 'mysql:host=127.0.0.1;port=9306;',
            'username' => asdasd,
            'password' => asd,
        ],

The site has a request form.
On local (Windows) everything works.
On the server (Debian) an error comes up:
Exception (Database Exception) "yii\db\Exception" with message "SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected
The SQL being executed was: SELECT `id`, `name`, `link` FROM `products`"

And on the server, I can connect to sphinx with:
mysql -h 127.0.0.1 --port=9306 -u asdasd -p asd

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Puma Thailand, 2015-11-09
@opium

So you have one port in the sphinx, and you connect to another

D
Daniel_Panov, 2019-11-21
@Daniil_Panov

In the config, specify the database in the dns parameter, i.e. instead of "mysql:host=127.0.0.1;port=9306" write "mysql:host=127.0.0.1;dbname=db_bayboow;port=9306".
In general, I had the same error, only everything was indicated there as it should

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question