Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex, DotBot

Members: 0
Guests: 1
Stats
Files
Topics
Posts
Members
Newest Member
481
3,734
19,366
618
Micheal64X
Today's Birthdays
Vintar (28)
Related Links
» SmaugMuds.org » General » Coding » MySQL issue
Forum Rules | Mark all | Recent Posts

MySQL issue
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Apr 18, 2008, 10:47 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Ahead of time, I'm not new to MUD Programming or MySQL stuff or anything by far, but this is just a little strange.

I'm using a SMAUG 1.4a MUD (DBSaga), and I can't seem to get MySQL to even connect at all.

Fri Apr 18 23:45:01 2008 :: Initializing database connections.
Fri Apr 18 23:45:01 2008 :: [*****] BUG: connect_db: error on connect
Fri Apr 18 23:45:01 2008 :: [*****] BUG: Access denied for user 'sessi'@'localhost' (using password: YES)

Yes, db name, username, password, etc, work just fine. I can connect with PHP and everything just fine. SMAUG 1.4a has the same issue, SMAUG 1.8 also does. I didn't try FUSS at all, however, MERC and ROM both work with SQL just fine. Even stranger, if I make it connect to a remote server elsewhere, it works just fine even with my Saga MUD. It's just trying to get it to connect to a local database that causes this, and it's not just the server, I've tried it on 3 different servers, and even on my personal linux PC.

Any help would be appreciated, Thanks.
       
Post is unread #2 Apr 18, 2008, 11:50 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

This is going to come down to what kind of SQL code you're using to try and connect, and how it's doing it. If you're getting problems across multiple codebases then it's time to start looking at the SQL layer. None of the codebases you've mentioned come stock with any kind of SQL support so the first question should be where you got the code from so we can take a look at it and see what it's doing.
       
Post is unread #3 Apr 19, 2008, 12:05 am   Last edited Apr 19, 2008, 12:07 am by Sessi
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

I stole my backend from one of my friends that I think stole his from the MudMagic snippet, but I'll post it:

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"
#include "sql_interface.h"
#include </usr/include/mysql/mysql.h>

void connect_db(){
	if ((result_db = mysql_init(NULL)) == NULL)
	{
		bug("connect_db: error on initialize", 0);
		return;
	}
	if (!mysql_real_connect(result_db, DB_HOST, DB_USER, DB_PASS, DB_DB, 0, NULL, CLIENT_FOUND_ROWS ))
	{
		bug("connect_db: error on connect", 0);
		bug(mysql_error(result_db), 0);
		mysql_close(result_db);
 		return;
	}

    if ((update_db = mysql_init(NULL)) == NULL)
    {
            bug("connect_db: error on initialize", 0);
            return;
    }
    if (!mysql_real_connect(update_db, DB_HOST, DB_USER, DB_PASS, DB_DB, 0, NULL, CLIENT_FOUND_ROWS ))
    {
            bug("connect_db: error on connect", 0);
            bug(mysql_error(update_db), 0);
            return;
    }
	db_connect = TRUE;
	return;
}

MYSQL_RES *query_db(char *query, MYSQL *m_db, bool sql_queue){
	return NULL;
	char buf[MAX_INPUT_LENGTH];

	buf[0] = '\0';

	if( !db_connect )
		connect_db();

	if( m_db == NULL){
		log_string("SQL-QUERY: Both connections must be present.";);
		return NULL;
	}
	if( query == NULL || query[0] == '\0'){
		log_string("Null query in query_db()";);
		return NULL;
	}

 	if (mysql_real_query(m_db, query, strlen(query))){
		log_string("query_db(): error on query";);
		log_string("-----------Error in MySQL------------";);
		log_string( mysql_error(m_db));
		return NULL;
	}
	return mysql_store_result(m_db);
}

char *sql_escape_string( char *source){
	return NULL;
	char *buf = '\0';
	char *ret = '\0';
	int len = 0;

	len = strlen( source );
	buf = malloc( (2 *len) + 1);
	mysql_real_escape_string( update_db, buf, source, len);
	ret = strdup( buf );
	free( buf );
	return ret;
}


#include </usr/include/mysql/mysql.h>

#define DB_HOST         "localhost"
#define DB_PORT         3306
#define DB_SOCKET       ""
#define DB_CLIENT_FLAG  0
#define DB_USER         "sessi"
#define DB_DB           "dbsaga"
#define DB_PASS         "password"

#define DB_CONNECT_TIME_LIMIT   5

MYSQL		*result_db;
MYSQL		*update_db;
MYSQL_RES	*query_db(char *query, MYSQL *m_db, bool sql_queue);
char    	*sql_escape_string(char *source);
bool		db_connect;
void		connect_db();


And in db.c I have the top of boot_db() to call
if(!db_connect){
	log_string( "Initializing database connections. ";);
		connect_db();	
}


I just don't see why it would work for ROM and MERC but not SMAUG and also why it works remotely, but not with localhost.

Erm, clarification, it works locally with ROM and MERC, but not SMAUG. It works remotely with all of them.
       
Post is unread #4 Apr 19, 2008, 2:08 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

If it helps any, this is the top portion of sql.cpp from AFKMud 2.0:

#include <cstdarg>
#include "mud.h"
#include "sql.h"

MYSQL myconn;

void init_mysql()
{
   if( !mysql_init( &myconn ) )
   {
      mysql_close( &myconn );
      bug( "%s: mysql_init() failed.", __FUNCTION__ );
      log_printf( "Error: %s.", mysql_error(&myconn) );
      return;
   }

   if( !mysql_real_connect( &myconn, sysdata->dbserver.c_str(), sysdata->dbuser.c_str(), sysdata->dbpass.c_str(), sysdata->dbname.c_str(), 0, NULL, 0 ) )
   {
      mysql_close( &myconn );
      bug( "%s: mysql_real_connect() failed.", __FUNCTION__ );
      log_printf( "Error: %s.", mysql_error(&myconn) );
      return;
   }
   mysql_options( &myconn, MYSQL_OPT_RECONNECT, "1" );
   log_string( "Connection to mysql database established." );
}


And this is what's in our sql.h file:
#ifndef __SQL_H__
#define __SQL_H__

#include <mysql/mysql.h>

extern MYSQL myconn;

/* mudsql.c */
void init_mysql( );
void close_db( );
int mysql_safe_query( const char *, ... );
void login_log( char_data *, int );
#endif


The only real difference I see is that your SQL code is trying to pass CLIENT_FOUND_ROWS which you haven't shown as defined anywhere. You're also passing NULL through to mysql_init() which looks wrong to me. See how ours uses a reference to the myconn variable? Then continues to pass that reference around to other SQL functions since it stores the connection it's trying to use.
       
Post is unread #5 Apr 19, 2008, 9:46 am
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Well, using the sql.cpp and sql.h from the AFKMud source, it still gives me the same exact issues with Saga and SMAUG, bleh.

I would try and see if AFKMud works, but the overland map screws up because of this servers lack of the gd-lib :/.

I really don't understand why this MySQL problem is occurring with me from what looks like only SMAUG though, and its really bothering with the remote working but not local, I just don't know what would be causing that.
       
Post is unread #6 Apr 19, 2008, 12:24 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Remote but not local could be caused by a number of things, like permissions in the database only allowing connections from specific IP addresses, of which localhost is not one of them. That doesn't really explain why ROM works locally but SMAUG doesn't, though.
       
Post is unread #7 Apr 19, 2008, 1:50 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Yeah, that's what was irking me, it works remotely but not locally, and ROM works. I see no differences in the SMAUG/ROM bases that would break SQL like this, bleh, this is getting really annoying.
       
Post is unread #8 Apr 19, 2008, 2:06 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Does the code return any kind of errors from the SQL layer? You should be getting something back from it indicating why it won't connect. It has to be something permissions related.
       
Post is unread #9 Apr 19, 2008, 2:34 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Nope, the error I posted is the only error I receive when trying.
       
Post is unread #10 Apr 19, 2008, 2:40 pm
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

I think Samson meant a return value or some other way of querying the SQL status, not the message that gets printed to the MUD log.
       
Post is unread #11 Apr 19, 2008, 2:52 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Oh, how would I go about doing that? I could tell ya then.
       
Post is unread #12 Apr 19, 2008, 7:44 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Fri Apr 18 23:45:01 2008 :: Initializing database connections.
Fri Apr 18 23:45:01 2008 :: [*****] BUG: connect_db: error on connect
Fri Apr 18 23:45:01 2008 :: [*****] BUG: Access denied for user 'sessi'@'localhost' (using password: YES)


Actually it appears I'm either a moron or blind, or both, but you already logged the problem. The 3rd line, where is says access denied, is the system telling you that something is not right. Either your user name is wrong for the DB connection, or the password is wrong. But it looks like either way something about it connecting to the DB with the information you've provided it is bad.
       
Post is unread #13 Apr 19, 2008, 10:06 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

That's what you'd think, but thats where the problem is; the information provided is perfectly correct. Even sending the same information over ROM it works just fine.

BLAH to this problem :((
       
Post is unread #14 Apr 23, 2008, 2:06 am
Go to the top of the page
Go to the bottom of the page

Caius
Magician
GroupMembers
Posts132
JoinedJan 29, 2006

Do you have access to the MySQL server log, such that you can look for additional information?
       
Post is unread #15 Apr 23, 2008, 6:40 am
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Unfortunately, no, I do not, I could host it up on my linux box and give you the logs from that if it produces any when I get home from school though.
       
Post is unread #16 Apr 24, 2008, 2:29 pm
Go to the top of the page
Go to the bottom of the page

Sessi
Fledgling
GroupMembers
Posts9
JoinedApr 18, 2008

Sorry for double post. Just thought I'd let you all know I solved the problem; I included OpenSSL in my libs and it fixed it.

Thanks for the help guys.
       
Post is unread #17 Jun 22, 2008, 9:55 am   Last edited Jun 22, 2008, 9:56 am by Noplex
Go to the top of the page
Go to the bottom of the page

Noplex
Apprentice
GroupMembers
Posts62
JoinedAug 30, 2005

I just worked heavily with the C API for MYSQL on a project for work. You will want to look into using prepared statements for most of (if not all) of your queries. I would suggest looking into MYSQL++ if you plan on using the g++ tool chain (which I think most of you do already). When working with prepared statements keep in mind that you want to go through the MYSQL API tutorials.

With that said, after reading the post it seems you merely have a credentials login problem. I should really read more than the title and the first couple of sentences. I'm lazy, what can I say.
       
Post is unread #18 Aug 27, 2008, 3:19 pm
Go to the top of the page
Go to the bottom of the page

Quixadhal
Conjurer
GroupMembers
Posts398
JoinedMar 8, 2005

Sorry to necro this thread but....

MySQL has a very strange view of permissions, and it's very possible for you to have given yourself access from a set of IP addresses, or even using a local socket, and yet NOT have permission from localhost.

Typically, the mysql command line client uses a local socket to connect, but I believe there are flags to force it to use an address and port.

If you can connect to the mysql database itself (mysql -p mysql), you can do a SELECT host,user from user; to see where you're authorized from. % is a wildcard for host, and quite often you'll see things like "10.0.0.%" or "%.domain".
       
Pages:<< prev 1 next >>