luasql and sphinxql

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

luasql and sphinxql

David Muscut
I want to script a query to a SphinxQL server (via the MySQL 4.1 transport protocol). I can query the server properly via the command line mysql client, but am unable to via luasql. Can someone point me to a working example of how to use luasql to query a sphinxql server?

The following works:
$ mysql -P9306 --protocol=tcp --prompt='sphinxQL> '

The following does not:
$ lua5.1
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> mysql = require "luasql.mysql"
> env  = mysql.mysql()
> = env:connect('localhost','9306')
nil    LuaSQL: error connecting to database. MySQL: Access denied for user '9306'@'localhost' (using password: NO)
> return  env:connect('user','pass','localhost','9306')
nil    LuaSQL: error connecting to database. MySQL: Can't connect to MySQL server on '9306' (22)

thanks!
-D

Reply | Threaded
Open this post in threaded view
|

Re: luasql and sphinxql

Philipp Janda
Am 13.10.2015 um 13:44 schröbte David Muscut:

> I want to script a query to a SphinxQL server (via the MySQL 4.1 transport
> protocol). I can query the server properly via the command line mysql
> client, but am unable to via luasql. Can someone point me to a working
> example of how to use luasql to query a sphinxql server?
>
> The following works:
> $ mysql -P9306 --protocol=tcp --prompt='sphinxQL> '
>
> The following does not:
> $ lua5.1
> Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
>> mysql = require "luasql.mysql"
>> env  = mysql.mysql()
>> = env:connect('localhost','9306')
> nil    LuaSQL: error connecting to database. MySQL: Access denied for user
> '9306'@'localhost' (using password: NO)
>> return  env:connect('user','pass','localhost','9306')
> nil    LuaSQL: error connecting to database. MySQL: Can't connect to MySQL
> server on '9306' (22)

The luasql documentation[1] says that the first argument (after `self`)
has to be the `sourcename` (I think that's the database name):

     env:connect(sourcename[,username[,password[,hostname[,port]]]])

>
> thanks!
> -D
>

Philipp

   [1]:
http://keplerproject.github.io/luasql/doc/us/manual.html#mysql_extensions




Reply | Threaded
Open this post in threaded view
|

Re: luasql and sphinxql

David Muscut
On Tue, Oct 13, 2015 at 4:34 PM, Philipp Janda <[hidden email]> wrote:

The luasql documentation[1] says that the first argument (after `self`) has to be the `sourcename` (I think that's the database name):

    env:connect(sourcename[,username[,password[,hostname[,port]]]])


Hi Philip,

I tried that as well, however when I use the index name lua can't connect to the sphinxql server. The other strange bit is that there is no authentication to the sphinxql server, while there is to mysql, however I get an access denied when I don't include the mysql credentials even though the connection request specifies the sphinxql server on port 9306.

- D
Reply | Threaded
Open this post in threaded view
|

Re: luasql and sphinxql

Philipp Janda
Am 13.10.2015 um 15:50 schröbte David Muscut:

> On Tue, Oct 13, 2015 at 4:34 PM, Philipp Janda <[hidden email]> wrote:
>
>>
>> The luasql documentation[1] says that the first argument (after `self`)
>> has to be the `sourcename` (I think that's the database name):
>>
>>      env:connect(sourcename[,username[,password[,hostname[,port]]]])
>>
>>
> Hi Philip,
>
> I tried that as well, however when I use the index name lua can't connect
> to the sphinxql server.

What is the index name?

> The other strange bit is that there is no
> authentication to the sphinxql server, while there is to mysql, however I
> get an access denied when I don't include the mysql credentials even though
> the connection request specifies the sphinxql server on port 9306.

All arguments except the `sourcename` are optional, so you could pass
`nil` for those (port should be 9306 of course). You can try passing the
empty string `""` as sourcename. Unfortunately, there is no way to force
TCP as transport protocol, but hopefully specifying a port (and maybe
"127.0.0.1" as hostname) will be sufficient.

Anyway, passing "localhost" (or "user") as sourcename won't do any good.

>
> - D
>

Good luck!

Philipp



Reply | Threaded
Open this post in threaded view
|

Re: luasql and sphinxql

Tomás Guisasola-2
In reply to this post by David Muscut
Hi David

On 2015-10-13 08:44, David Muscut wrote:
> I want to script a query to a SphinxQL server (via the MySQL 4.1
> transport protocol). I can query the server properly via the command
> line mysql client, but am unable to via luasql. Can someone point me
> to a working example of how to use luasql to query a sphinxql server?
Are you sure this is possible?  Note that LuaSQL's MySQL driver is just
a bind to the C API.  When you try to connect to the database, you are
calling mysql_real_connect with the same parameters provided to Lua and
some default: the unix_socket will be always NULL and the client_flag
will be always 0.  The driver also does not provide any support for
using mysql_options.

> The following works:
> $ mysql -P9306 --protocol=tcp --prompt='sphinxQL> '
It seems that the --protocol=tcp is important when using mysql client,
but I am not sure if this affects LuaSQL usage.

> The following does not:
> $ lua5.1
> Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
>> mysql = require "luasql.mysql"
>> env  = mysql.mysql()
>> = env:connect('localhost','9306')
> nil    LuaSQL: error connecting to database. MySQL: Access denied for
> user '9306'@'localhost' (using password: NO)
>> return  env:connect('user','pass','localhost','9306')
> nil    LuaSQL: error connecting to database. MySQL: Can't connect to
> MySQL server on '9306' (22)
As Phillip Janda already mentioned, you are using the connect method
incorrectly, unless your database is called 'localhost' and your user is
called '9306' :-)  You have to provide the strings for each argument or
nil:

connection = env:connect("database-name", "username", "password", nil,
9306)

Have you tried something like that?

Regards,
Tomás

Reply | Threaded
Open this post in threaded view
|

Re: luasql and sphinxql

David Muscut
In reply to this post by Philipp Janda
Thanks, that did the trick. In case this helps anyone else I used the following code:

$ lua5.1
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> mysql = require "luasql.mysql"
> env  = mysql.mysql()
> conn, e = env:connect('test1','','','127.0.0.1','9306')

...

On Tue, Oct 13, 2015 at 5:47 PM, Philipp Janda <[hidden email]> wrote:
Am <a href="tel:13.10.2015" value="+13102015" target="_blank">13.10.2015 um 15:50 schröbte David Muscut:
On Tue, Oct 13, 2015 at 4:34 PM, Philipp Janda <[hidden email]> wrote:


The luasql documentation[1] says that the first argument (after `self`)
has to be the `sourcename` (I think that's the database name):

     env:connect(sourcename[,username[,password[,hostname[,port]]]])


Hi Philip,

I tried that as well, however when I use the index name lua can't connect
to the sphinxql server.

What is the index name?

The other strange bit is that there is no
authentication to the sphinxql server, while there is to mysql, however I
get an access denied when I don't include the mysql credentials even though
the connection request specifies the sphinxql server on port 9306.

All arguments except the `sourcename` are optional, so you could pass `nil` for those (port should be 9306 of course). You can try passing the empty string `""` as sourcename. Unfortunately, there is no way to force TCP as transport protocol, but hopefully specifying a port (and maybe "127.0.0.1" as hostname) will be sufficient.

Anyway, passing "localhost" (or "user") as sourcename won't do any good.


- D


Good luck!

Philipp