lapis icon indicating copy to clipboard operation
lapis copied to clipboard

mysql db connection fails

Open VaiN474 opened this issue 6 years ago • 0 comments

I'm unable to connect to a mysql database in Lapis or while attempting a migration.

LuaSQL: error connecting to database. MySQL: Access denied for user 'root'@'localhost' (using password: YES)

Yet, I can connect just fine via mysql on the CLI using mysql -u root -p with the same credentials. When the migration failed I ran it again with --trace and it pointed to the script that handles the connection. I then attempted the connection line-by-line in LuaJIT CLI in my project's root:

»[vain]╺─╸[dev][$] luajit
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> config = require("lapis.config").get()
> mysql_config = assert(config.mysql, "missing mysql configuration")
> luasql = require("luasql.mysql").mysql()
> conn_opts = {
>> mysql_config.database,
>> mysql_config.user,
>> mysql_config.password
>> }
> if mysql_config.host then
>> table.insert(conn_opts, mysql_config.host)
>> if mysql_config.port then
>> table.insert(conn_opts, mysql_config.port)
>> end
>> end
> conn = assert(luasql:connect(unpack(conn_opts)))
stdin:1: LuaSQL: error connecting to database. MySQL: Access denied for user 'root'@'localhost' (using password: YES)
stack traceback:
	[C]: in function 'assert'
	stdin:1: in main chunk
	[C]: at 0x004044a0
> = conn_opts[1]
dbname
> = conn_opts[2]
root
> = conn_opts[3]
dbpass
> = conn_opts[4]
localhost
> = conn_opts[5]
3306
> 
> conn = assert(luasql:connect("dbname","root","dbpass","localhost",3306))
> = conn
MySQL connection (0x40ea9280)
> conn:close()
> luasql:close()
> = conn
MySQL connection (closed)
> = luasql
MySQL environment (closed)

As you can see, the credentials are gathered from the config correctly. But for whatever reason the connection fails. So I then attempted the connection with the literal credentials, and it connected fine. I also went back and made sure there's no extra spaces in any values or anything like that. There's no symbols in any of the credentials either.

The connection never fails when using literal credentials, but using the info from the config fails, even though it looks correct. Something wrong with my config maybe?

-- config.lua

local config = require("lapis.config")

config("development", {
  host = "localhost",
  lua_code_cache = "off",
  port = 8080,
  num_workers = "1",
  session_name = "devsession",
  _name = "development",
  mysql = {
    host = "localhost",
    user = "root",
    password = "dbpass",
    database = "dbname",
    port = 3306
  }
})

Anyone know what might be causing the issue?

VaiN474 avatar Jul 31 '17 20:07 VaiN474