Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to install lua-sql #26

Closed
swaroopsp opened this issue Jan 19, 2015 · 32 comments
Closed

Not able to install lua-sql #26

swaroopsp opened this issue Jan 19, 2015 · 32 comments

Comments

@swaroopsp
Copy link

I tried to install luasql both mysql and jdbc version. I am struggling to install these. Spent days doing this. Will Appreciate any help. I installed LUA 5.1 from
https://code.google.com/p/luaforwindows/downloads/list

1. lua-jdbc

C:\Program Files (x86)\LuaRocks\2.2>luarocks install luasql-jdbc

Error: No results matching query were found.

2. lua-mysql

C:\Program Files (x86)\LuaRocks\2.2>luarocks install luasql-mysql
Installing https://rocks.moonscript.org/luasql-mysql-2.3.0-1.src.rock...
Using https://rocks.moonscript.org/luasql-mysql-2.3.0-1.src.rock... switching to 'build' mode

Error: Could not find expected file mysql.h, or mysql.h for MYSQL -- you may have to install MYSQL in your system and/or pass MYSQL_DIR or MYSQL_INCDIR to the luarocks command. Example: luarocks install luasql-mysql MYSQL_DIR=/usr/local

I tried to install with MYSQL_DIR. But no help

@hishamhm
Copy link
Member

Do you have a C compiler (such as Visual Studio) setup in your environment? You will need it to compile LuaSQL.

Locate where in your system you have the files mysql.h and mysqlclient.dll. Suppose they are in c:\foo\ and c:\bar\ respectively. Then run luarocks like this:

luarocks install luasql-mysql MYSQL_INCDIR=c:\foo MYSQL_LIBDIR=c:\bar

If the files are under directories with spaces in their names (such as c:\ Program Files (x86)\MySQL\) you'll have to use quotes, but I'm not knowledgeable of the specific quoting style needed in the Windows shell...

@ghost
Copy link

ghost commented Jul 24, 2016

Hi,
I can't find mysqlclient.dll (there is only *.lib version) even I have mysql server 5.7 and mysql connector/c installed. Please could you help me exactly which version of mysql I have to download or if I have to compile mysql from sources.

@ghost
Copy link

ghost commented Jul 25, 2016

OK, there is no file mysqlclient.dll in MySQL for Windows distribution. Right file name to link with Luarocks' luasql-mysql is libmysql.dll. Current rockspec never compile on windows. You must replace "mysqlclient" with "libmysql" in luasql-mysql rockspec. Use cvs-1 version.

@bonez001
Copy link

Hello. I am installing mysql via luarocks. I followed the instruction in this thread and I got the following error:

screenshot 2016-10-12 14 48 17

I use this code:

luarocks install luasql-mysql MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Connector.C 6.1\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Connector.C 6.1\lib"

.

I found mysql.h and libmysql.dll.

@ghost
Copy link

ghost commented Oct 12, 2016

@bonez001
Copy link

Thank you so much. I followed kinda understand the instruction. Why am I still getting this?

screenshot 2016-10-12 16 12 22

@bonez001
Copy link

Hello I finally installed luasql I think. Now the problem is I can't seem to run luasql-mysql. I added some images:

After Installation
screenshot 2016-10-12 17 37 12

and

Running luasql-mysql
screenshot 2016-10-12 18 10 45.

It seems like I only have mysql.dll after installation. The link you gave really help. Thanks a lot.

@mpeterv
Copy link
Contributor

mpeterv commented Oct 12, 2016

Try require("luasql.mysql").

@bonez001
Copy link

Hello. I tried running it but at least I have new error.
screenshot 2016-10-13 14 29 22.
By the way I have a question regarding luasql-mysql-cvs-1.rockspec. Does the sources and header need the actual location of the files?

package = "LuaSQL-MySQL"
version = "cvs-1"
source = {
url = "git://github.com/keplerproject/luasql.git"
}
description = {
summary = "Database connectivity for Lua (MySQL driver)",
detailed = [[
LuaSQL is a simple interface from Lua to a DBMS. It enables a
Lua program to connect to databases, execute arbitrary SQL statements
and retrieve results in a row-by-row cursor fashion.
]],
license = "MIT/X11",
homepage = "http://www.keplerproject.org/luasql/"
}
dependencies = {
"lua >= 5.1"
}
external_dependencies = {
MYSQL = {
header = "mysql.h"
}
}
build = {
type = "builtin",
modules = {
["luasql.mysql"] = {
sources = { "C:/Users/pc/Desktop/luasql-master/src/luasql.c", "C:/Users/pc/Desktop/luasql-master/src/ls_mysql.c" },
libraries = { "libmysql" },
incdirs = { "$(MYSQL_INCDIR)" },
libdirs = { "$(MYSQL_LIBDIR)" }
}
}
}

@tomasguisasola
Copy link
Contributor

Hi bonez001

This message ("The specified module could not be found") does not seem
to be emitted by Lua, although the message "error loading module" was
emitted by Lua (check function loaderror in src/loadlib.c). It seems
that require() found the file, load it, called the correct C function
(luaopen_luasql_mysql) but that function produced the error... I am
sorry I don't have the appropriate Windows knowledge to help you, but
that's my suspect: the link process. Could you send the output the
compiler/linker produced?

Regards,
Tomás

On 2016-10-13 03:32, bonez001 wrote:

Hello. I tried running it but at least I have new error.
[1].
By the way I have a question regarding luasql-mysql-cvs-1.rockspec.
Does the sources and header need the actual location of the files?

package = "LuaSQL-MySQL"
version = "cvs-1"
source = {
url = "git://github.com/keplerproject/luasql.git"
}
description = {
summary = "Database connectivity for Lua (MySQL driver)",
detailed = [[
LuaSQL is a simple interface from Lua to a DBMS. It enables a
Lua program to connect to databases, execute arbitrary SQL statements
and retrieve results in a row-by-row cursor fashion.
]],
license = "MIT/X11",
homepage = "http://www.keplerproject.org/luasql/ [2]"
}
dependencies = {
"lua >= 5.1"
}
external_dependencies = {
MYSQL = {
header = "mysql.h"
}
}
build = {
type = "builtin",
modules = {
["luasql.mysql"] = {
sources = { "C:/Users/pc/Desktop/luasql-master/src/luasql.c",
"C:/Users/pc/Desktop/luasql-master/src/ls_mysql.c" },
libraries = { "libmysql" },
incdirs = { "$(MYSQL_INCDIR)" },
libdirs = { "$(MYSQL_LIBDIR)" }
}
}
}

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub [3], or mute the
thread [4].

Links:

[1]
https://cloud.githubusercontent.com/assets/20276137/19338754/995ee03e-9151-11e6-8676-b49d075d5a47.png
[2] http://www.keplerproject.org/luasql/
[3]
#26 (comment)
[4]
https://github.com/notifications/unsubscribe-auth/AAIA7edIgFArxTYCgYWRlJK0P-oZrcihks5qzdCTgaJpZM4DUN-n

@bonez001
Copy link

What is the compiler/linker? How can I run it? Do you think it is better to use other OS?

@tomasguisasola
Copy link
Contributor

Hi bonez001

What is the compiler/linker? How can I run it? Do you think it is
better to use other OS?
The compiler is the program that transforms (compiles) the source code
(.c and .h) into object code (.obj). The linker is the program that
joins some object files with library files (.lib or .dll) and produce
the executable (.exe).

There is an important difference between those two types of libraries.
Static libraries (.lib) are code that might be copied toghether to the
final executable, while dynamic libraries (.dll) are not, because
dynamic libraries are shared between many programs. To make that
architecture work, the linker has to point to the correct places in
memory to find the functions it has to call. And, since dynamic
libraries are loaded dynamically (i.e. loaded only when the program
runs), you only know if it works when running the program.

Another important thing to know is if your Lua executable was linked to
a static library or to a dynamic one. If it was linked to a static
library, the code is inside the executable and it should be built with
the ability to export those symbols. The linker should use those
symbols when linking new libraries (which depend on the same static
library mentioned above). If your Lua executable was linked to a
dynamic Lua library, your new library should be linked to that same
library too.

Your linker (Microsoft (R) Incremental Linker Version 14.00.24215.1,
named 'link' in your terminal) is linking the driver (luasql/mysql.dll)
to lua5.1.lib (at C:/gcc-lua-install/lua-5.1/src/lua5.1.lib, as shown in
the terminal screen dump), but maybe the driver should be linked to a
dynamic version (lua5.1.dll ???)

It would be better to hear from someone with more knowledge of
Windows...

Regards,
Tomás

@hishamhm
Copy link
Member

By the way I have a question regarding luasql-mysql-cvs-1.rockspec. Does the sources and header need the actual location of the files?

No, that is not necessary (or recommended!).

@brydavis
Copy link

This worked for me (Mac OS; MySQL and Lua installed via Homebrew):
luarocks install luasql-mysql MYSQL_INCDIR=/usr/local/include/mysql;

@mccrafter1212
Copy link

mccrafter1212 commented Dec 18, 2017

@bonez001 How'd you fix your issue (Click to view image)? I'm having this same issue but have no clue how to resolve it. Please help :/

Also sorry for reviving a dead issue

@Fantalic
Copy link

Fantalic commented Jul 2, 2018

I also get a error while installing via luarocks under windows:
"
cl /nologo /MD /O2 -c -Fosrc/luasql.obj -ID:/.../include src/luasql.c -Ic:/external/include
Der Befehl "cl" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
// cl comand not found

Error: Build error: Failed compiling object src/luasql.obj
"

@tomasguisasola
Copy link
Contributor

tomasguisasola commented Jul 2, 2018 via email

@Fionnghall
Copy link

Fionnghall commented Nov 2, 2019

Do you have a C compiler (such as Visual Studio) setup in your environment? You will need it to compile LuaSQL.

Locate where in your system you have the files mysql.h and mysqlclient.dll. Suppose they are in c:\foo\ and c:\bar\ respectively. Then run luarocks like this:

luarocks install luasql-mysql MYSQL_INCDIR=c:\foo MYSQL_LIBDIR=c:\bar

If the files are under directories with spaces in their names (such as c:\ Program Files (x86)\MySQL\) you'll have to use quotes, but I'm not knowledgeable of the specific quoting style needed in the Windows shell...

@hishamhm Thank you very much

@ankitbondwal
Copy link

Hello I finally installed luasql I think. Now the problem is I can't seem to run luasql-mysql. I added some images:

After Installation
screenshot 2016-10-12 17 37 12

and

Running luasql-mysql
screenshot 2016-10-12 18 10 45.

It seems like I only have mysql.dll after installation. The link you gave really help. Thanks a lot.

Hi, please let me know the steps of installing luasql

@ankitbondwal
Copy link

i really appreciate the help

@Fionnghall
Copy link

i really appreciate the help

  1. remove all lua-related
  2. install luaforwindows from here.
    luaforwindows
  3. environment variable configuration LUA_CPATH
  4. You got it.
    1)0)P{ 0TS_8JX2L7J9 KQH
    image

@tomasguisasola
Copy link
Contributor

Hi Ankit

It seems you have successfully installed luasql-mysql, but could not attempt to load it (with require). But note that there are two important lines of information at the end of the installing process:

Creating library luasql/mysql.lib

luasql-mysql cvs-1 is now installed in C:\gcc-lua-install\lua-5.1\src\systree

The first one shows the name of the file produced and the last one shows that you choose a very old version (cvs-1, we are at 2.6 now) and that it was installed at "C:\gcc-lua-install\lua-5.1\src\systree". This "systree" surprises me! Could you check if there is such a path?

I recommend you read the message that function require emmited carefully. The Lua Team have expended a great effort in providing us many importante information! Note that the function searches for a file called "luasql-mysql.dll" which is the wrong file name. You should load the module with:

mysql = require"luasql.mysql"

The variable mysql would store a reference to the module's table.

Regards,
Tomás

@alex1543
Copy link

alex1543 commented Apr 14, 2023

Dear Developers,

Help to connect the module to the Apache server. Configured httpd.conf, enabled modules:
LoadModule lua_module modules/mod_lua.so
LoadModule dbd_module modules/mod_dbd.so
I execute the script through Apache:
function handle(r)
mysql = require "luasql.mysql"
local env = mysql.mysql()
local conn = env:connect('test','root','')
print(env,conn)
status,errorString = conn:execute([[CREATE TABLE sample2 (id INTEGER, name TEXT);]])
print(status,errorString)
end

I am getting an error:
error!
C:/xampp/htdocs/lua/mysql.lua:5: module 'luasql.mysql' not found:
no field package.preload['luasql.mysql']
no file 'C:\xampp\apache\bin\lua\luasql\mysql.lua'
no file 'C:\xampp\apache\bin\lua\luasql\mysql\init.lua'
no file 'C:\xampp\apache\bin\luasql\mysql.lua'
no file 'C:\xampp\apache\bin\luasql\mysql\init.lua'
no file '.\luasql\mysql.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\luasql\mysql.luac'
no file 'C:\xampp\apache\bin\luasql\mysql.dll'
no file 'C:\xampp\apache\bin\loadall.dll'
no file '.\luasql\mysql.dll'
no file 'C:\xampp\apache\bin\luasql.dll'
no file 'C:\xampp\apache\bin\loadall.dll'
no file '.\luasql.dll'

I installed Lua separately and everything works there, the luasql.mysql module is located.

Help, please, to connect luasql through Apache.

@tomasguisasola
Copy link
Contributor

Hi Alexey

It seems you are taking modules/mod_dbd.so as LuaSQL, but it is not. If you need LuaSQL you'll have to install it too. I recomend you intall LuaRocks (https://luarocks.org/) first and then use it to install other Lua packages (also known as rocks).

Regards,
Tomás

@alex1543
Copy link

LuaSQL is installed in a separate installation copy C:\Program Files (x86)\Lua\5.1\lua\luasql . Through the program "lua hello.lua" everything works. Doesn't work through the Apache 2.4 module that comes with it in the C:\xampp\apache\modules\mod_lua.so installation.

Do I need to put something in httpd.conf to make linking to C:\Program Files (x86)\Lua\5.1\lua\luasql work?

@alex1543
Copy link

The problem was partially solved with the help of the LUA_CPATH environment variable, which pointed to: C:\Program Files (x86)\Lua\5.1\clibs?.dll;C:\Program Files (x86)\Lua\5.1\clibs\luasql\ ?.dll
But now there is another problem: error loading module 'luasql.mysql' from file 'C:\Program Files (x86)\Lua\5.1\clibs\luasql\mysql.dll':
%1 is not a Win32 application.

Is there a 64 bit version of LuaSQL compilation?

@alex1543
Copy link

I installed Apache x86 as an experiment. Now there is no message, but hangs on the line "mysql = require "luasql.mysql"". Browser message: "Unable to access site. Connection reset.". Connection code:

function handle(r)

r.content_type = "text/html"
r:puts("ok") -- it works

package.cpath = package.cpath .. ";C:/Program Files (x86)/Lua/5.1/lua/luasql/?.dll"
mysql = require "luasql.mysql" -- hangs here
local env = mysql.mysql()
local conn = env:connect('test','root','','localhost',3306)

cursor,errorString = conn:execute([[select * from myarttable]])
row = cursor:fetch({}, "a")

while row do
print(string.format("id: %s, text: %s, description: %s, keywords: %s", row.id, row.text, row.description, row.keywords))
row = cursor:fetch(row, "a")
end

end

From the console, the code runs without the error "lua exLuaSQL.lua" without declaring function handle(r). What could be the problem?

@tomasguisasola
Copy link
Contributor

Hi Alexey

The path you added to package.cpath is useless (assuming the file is in C:/Program Files (x86)/Lua/5.1/lua/luasql/mysql.dll). That line should be:

package.cpath = package.cpath .. ";C:/Program Files (x86)/Lua/5.1/lua/?.dll"

When require"luasql.mysql" is executed, the '.' in the name of the module would be substituted by the directory separator, '/' or '' or whatever the OS standard is. Thus the '?' will be substituted by "luasql/mysql" and the file will be loaded from "C:/Program Files (x86)/Lua/5.1/lua/luasql/mysql.dll".

I hope the correction above will solve your problem.

Regards,
Tomás

@alex1543
Copy link

Dear Tomás,

The old error reappears:
image

image

@tomasguisasola
Copy link
Contributor

Hi Alexey,

Please check if the file is in C:/Program Files (x86)/Lua/5.1/lua/luasql/mysql.dll as I supposed it should be.

If it is not, I recommend you correct the package.cpath accordingly.

If the file is there, it seems the Apache Lua Module have a different require() than the command line Lua interpreter...

Regards,
Tomás

@alex1543
Copy link

alex1543 commented May 2, 2023

Dear Tomás,

the file exists. The problem was solved through my web server on require("socket") without using the module for Apache. Thanks for the help!

Sincerely,
Alexei

@tomasguisasola
Copy link
Contributor

Thus, i think we can end this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests