• MySQL with server
    22 replies, posted
Would anyone care to explain to me how to connect my dedicated server to a mysql database for things like ULX Global Ban, I cant seem to get it to connect with the server. If we could talk through skype it would be easier, not video/voice chat just text. My skype username is chris.v49. Please help I need to improve my server, Thanks.
First you need a libmysql.dll, and you put that DLL in the same directory as hl2.exe and srcds.exe. Lets call that Z:/server/ for simplicity. Next, under Z:/server/garrysmod/lua/bin/ you need to install a MySQL DLL. I use TMySQL 4 BOOST: gmsv_tmysql4_win32.dll There are others that work, such as TMySQL 3 ( gmsv_tmysql3_win32.dll ), MySQLOO ( gmsv_mysqloo_win32.dll ) but they all require the libmysql.dll. Once you have those in place, you need to create a lua file called on the SERVER. You will need to [lua]require("tmysql4"); or require("tmysql3"); or require("mysqloo");[/lua] Then, you will need to ( for tmysql3 and 4 / Unsure for mysqloo, I don't have that one set up at the moment but it's pretty similar ): [lua]DATABASE, ERR = tmysql.initialize( ip, user, pass, database_name, port, 2, 2 )[/lua] Then you can start using, as long as there were no errors connecting, DATABASE:Query( "SQL", funcOnSuccess, funcOnFail );
[QUOTE=Acecool;41715782]First you need a libmysql.dll, and you put that DLL in the same directory as hl2.exe and srcds.exe. Lets call that Z:/server/ for simplicity. Next, under Z:/server/garrysmod/lua/bin/ you need to install a MySQL DLL. I use TMySQL 4 BOOST: gmsv_tmysql4_win32.dll There are others that work, such as TMySQL 3 ( gmsv_tmysql3_win32.dll ), MySQLOO ( gmsv_mysqloo_win32.dll ) but they all require the libmysql.dll. Once you have those in place, you need to create a lua file called on the SERVER. You will need to [lua]require("tmysql4"); or require("tmysql3"); or require("mysqloo");[/lua] Then, you will need to ( for tmysql3 and 4 / Unsure for mysqloo, I don't have that one set up at the moment but it's pretty similar ): [lua]DATABASE, ERR = tmysql.initialize( ip, user, pass, database_name, port, 2, 2 )[/lua] Then you can start using, as long as there were no errors connecting, DATABASE:Query( "SQL", funcOnSuccess, funcOnFail );[/QUOTE] What does the lua file need to be called? and where should it go?
You can name it anything you want, but you need to include( ) it, if you put it in your game-mode directory, only on the SERVER side because it contains password ( sensitive data, not for the client ). If you want, you could put it into garrysmod/addons/database_addon_new_name_whatever/lua/autorun/server/file.lua and put the content in there. Also, have your code execute on Initialize. You won't have to reinitialize on change-level. [lua]hook.Add("Initialize", "DatabaseStuff", function( ) end );[/lua]
[QUOTE=Acecool;41715904]You can name it anything you want, but you need to include( ) it, if you put it in your game-mode directory, only on the SERVER side because it contains password ( sensitive data, not for the client ). If you want, you could put it into garrysmod/addons/database_addon_new_name_whatever/lua/autorun/server/file.lua and put the content in there. Also, have your code execute on Initialize. You won't have to reinitialize on change-level. [lua]hook.Add("Initialize", "DatabaseStuff", function( ) end );[/lua][/QUOTE] ok thanks for the help so far, it says success but the database still says cant connest, any ideas? [editline]4th August 2013[/editline] connect and its still not working it says cant connect to mysql server on 127.0.0.1
is the mysql database on the dedi or on like a web server?
[QUOTE=ikoN420;41716332]is the mysql database on the dedi or on like a web server?[/QUOTE] dedi
can you paste the exact error?
[CODE]==[ Version Info ]============================== MySQLoo Version: 8 Client Version: 60000 Client Info: 6.0.0 *** SUCCESS *** ==[ Connect ]============================== [Database:1FB07D70] Connection to Steam servers successful. Public IP is 47.17.113.61. Assigned anonymous gameserver Steam ID [A-1:3777204225(3562)]. VAC secure mode is activated. bot ServerLog: Bot01 (BOT) Spawned for the first time ServerLog: Bot01 (BOT) Spawned *** FAILURE *** Can't connect to MySQL server on '192.168.1.xxx' (10061) ServerLog: Bot01 (BOT) Attempted to pick up a keys ServerLog: Bot01 (BOT) Attempted to pick up a weapon_physcannon ServerLog: Bot01 (BOT) Attempted to pick up a gmod_camera ServerLog: Bot01 (BOT) Attempted to pick up a gmod_tool ServerLog: Bot01 (BOT) Attempted to pick up a pocket ServerLog: Bot01 (BOT) Attempted to pick up a weapon_physgun ServerLog: Bot01 (BOT) Attempted to pick up a fists_weapon Writing cfg/banned_user.cfg. Connection failed! Can't connect to MySQL server on '127.0.0.1' (10061)Spawning textscreens... Spawned 6 textscreens for map rp_downtown_v4c_v2 [/CODE] I put the xxx in ip for security reasons
pssst you forgot to remove your public IP (assuming you don't want that released either)
[QUOTE=Luni;41717721]pssst you forgot to remove your public IP (assuming you don't want that released either)[/QUOTE] Public ip is fine nobody can do anything with that, that is servers IP it is public anyone can see it who joins the server, thanks for the concern though.
Does your MySQL server allow for remote connections? Here's a tutorial on how to allow Remote connections if they're disabled. [url]http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html[/url]
bad thing is i cant find the file haha im on windows 7
For Windows, I believe its my.ini :: PATH TO localhost\bin\mysql\mysql Make sure that the USER assigned to the database has all access, port 3306 unblocked in the firewall and my.ini path above... Here's a link: [url]http://www.razorsql.com/docs/support_mysql_local.html[/url] To enable networking manually, make sure the skip-networking line is commented out, and the following line is contained in the file with the SERVER-IP replaced with the actual ip address of the server: bind-address=SERVER-IP
hold on i think i got it
Am I the only one not noticing he's concerned about hiding the last octet of his LAN IP for "security reasons"?
Ok i believe im on the right track only thing i think is bad is that skip networking line i dont know where it is [editline]5th August 2013[/editline] forget it this doesnt even make sense for me to do im on the same computer so it wouldnt help [editline]5th August 2013[/editline] now i see what i suppose is a default set of tables in the connection in mysql but when i try putting the server to the same connection no new tables or anything shows up and it says failed to connect but i still have the mysql tables
my.ini file located in the mysql install dir: basedir=c:/localhost/bin/mysql/mysql5.1.36 [lua]# Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (via the "enable-named-pipe" option) will render mysqld useless! # #skip-networking[/lua]
This is what im getting [CODE] Connection to database failed! Error: Unknown database 'darkrp' Connection to Steam servers successful. Public IP is 47.17.113.61. Assigned anonymous gameserver Steam ID [A-1:3725289473(3563)]. VAC secure mode is activated. [/CODE]
You need to create that database. It doesn't exist. A database holds tables. Tables hold rows / columns of info.
and how would i do that?
You do have the LibMySQL.dll where the game/server exe is right? [url]http://facepunch.com/showthread.php?t=1220537[/url] it's at the bottom [URL="http://puu.sh/1fhWu"]Windows[/URL]
yes [editline]5th August 2013[/editline] OK i got database connected! Now can i view it from navicat? [editline]5th August 2013[/editline] oh i got it thanks so much now im just gonna go install uban and u time and stuff thanks so much everyone whi helped i've wanted to get this working badly, Ace youve done it again
Sorry, you need to Log In to post a reply to this thread.