Sign in to follow this  

Problems with mysql connection

Recommended Posts

Dear users,

I created a test resource called "prova". When I try to start it, I get this error:

[12:50:25] start: Requested by Console
[12:50:25] Resource 'prova' changed, reloading and starting
[12:50:25] Starting prova
[12:50:25] WARNING: [mie]/prova/mysql.lua:4: Bad usage @ 'dbConnect' [Can't connect to local MySQL s
erver through socket '' (111)]
[12:50:25] start: Resource 'prova' started

As it appears, the problem is in the mysql.lua file, executed serverside, this is the code:

db = nil

function conn()
db = dbConnect('mysql', 'dbname=mtasa;host=localhost;port=3306;', 'mtasa', '', "share=1")

function disc()

function segnalo(msg, tipo)
dbExec(db, 'INSERT INTO provatab(testo, soldi, spotf) VALUES(?, ?, ?)', 'Msg-'..tostring(tipo)..': '..msg, 2500, 1)

function giraarma(prima, mo)
dbExec(db, 'INSERT INTO provatab(testo, soldi, spotf) VALUES(?, ?, ?)', 'Arma da '..tostring(prima)..' a '..tostring(mo)..' - Chi: '..getPlayerName(source), 2500, 1)

addEventHandler('onResourceStart', getResourceRootElement(), conn)
addEventHandler('onResourceStop', getResourceRootElement(), disc)
addEventHandler("onPlayerChat", getRootElement(), segnalo)
addEventHandler("onPedWeaponSwitch", getRootElement(), giraarma)

I thought it could be a mysql problem, but when I try to access to my database via phpmyadmin on localhost server, I can access without problems.


What can it be?


Please help!

Share this post

Link to post

You are missing the unix socket boy. If you don't know where it is, just connect to the mySQL by using your host public IP.

Share this post

Link to post

Actually, I'm developing/testing my MTA server in LAN, then without public IP, and then I don't want to grant mysql connections outside localhost, due to security problems.

How can I fix this issue (unix socket) using localhost address?



Share this post

Link to post

I solved the problem changing the old dbConnect() code with this:

db = dbConnect('mysql', 'dbname=mtasa;host=localhost;port=3306;unix_socket=/var/run/mysqld/mysqld.sock;charset=utf8;', 'mtasa', '', "share=1;autoreconnect=1;")


Now if you want, you can trash this topic.


Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.