Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


MySQL Database - Frustrating connection problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 pifreak   Members   -  Reputation: 111

Like
0Likes
Like

Posted 21 June 2012 - 09:48 AM

Hello fellow developers,

I have searched the topics and not found what I need so I'm making this post.
I have made an online RPG game that uses MySQL for a database.

Everything works fine. Transactiosn are solid. Upon losing connections it reconnects fine.
I've had an experienced programmer friend look over the code and he says it looks correct.

The problem is, why does the program disconnect form MySQL? It happens often if it is connecting to a remote database, however right now it's connecting to a local database. I do not really know much about MySQL config or how to do it properly.

There are conflicting opinions and suggestions across the web...

Server Setup:
Amazon EC2 Small (Default) instance 1.7GB ram
Linux Server distro - Ubuntu Server 12.04 LTS

Game Server:
C++ native Linux program powered by the MySQL C API.


MySQL Setup:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port		    = 3306
socket		  = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket		  = /var/run/mysqld/mysqld.sock
nice		    = 0
[mysqld]
#
# * Basic Settings
#
user		    = mysql
pid-file	    = /var/run/mysqld/mysqld.pid
socket		  = /var/run/mysqld/mysqld.sock
port		    = 3306
basedir		 = /usr
datadir		 = /var/lib/mysql
tmpdir		  = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		    = 10.190.89.159
#
# * Fine Tuning
#
key_buffer			  = 64M
max_allowed_packet	  = 16M
thread_stack		    = 192K
thread_cache_size	   = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover		 = BACKUP
#max_connections	    = 100
#table_cache		    = 64
#thread_concurrency	 = 10
#
# * Query Cache Configuration
#
query_cache_limit	   = 128M
query_cache_size	    = 64M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file	    = /var/log/mysql/mysql.log
#general_log			 = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#log_slow_queries	   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#	   other settings you may need to change.
#server-id			  = 1
#log_bin					    = /var/log/mysql/mysql-bin.log
expire_logs_days	    = 7
max_binlog_size		 = 100M
#binlog_do_db		   = include_database_name
#binlog_ignore_db	   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

[mysqldump]
quick
quote-names
max_allowed_packet	  = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer			  = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

The disconnects print out errors such as:
"Lost connection to MySQL Server during query!"
"The MySQL Server has gone away!"

This issue is not urgent but I do not quite understand why it would disconnect from a local database. And I do appreciate the help if anyone wishes to. :)


Thank you so much!

pi`

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5514

Like
0Likes
Like

Posted 21 June 2012 - 11:34 AM

First, be very careful about your data on the ECC. An instance may just go away, and if your database was running on local disk on that isntance, it's forever gone. ECC has two other options to solve this: Elastic Block Store, or the Relational Database Service.

Second, MySQL will disconnect if there is a network problem, or if a connection stays idle for too long.
enum Bool { True, False, FileNotFound };

#3 pifreak   Members   -  Reputation: 111

Like
0Likes
Like

Posted 21 June 2012 - 12:10 PM

The server is running on an EBS volume, so everything's safe.
There isn't a network problem because it's connecting to localhost.
The connection is not idle too long. There is a query every 5 minutes and frequent pings to check if the connection is alive.

Is something configured wrong in the my.cnf you see above?


pi`

Edited by pifreak, 21 June 2012 - 03:25 PM.


#4 Firestryke31   Members   -  Reputation: 350

Like
0Likes
Like

Posted 21 June 2012 - 08:11 PM

Is the code you're writing for the client, or your server program that needs to store persistant data in the DB? If it's the server, and the server is going to be on a different machine than the DB, is the DB configured to allow remote connections from the server's machine? If it's the client, slap yourself on the wrist and rethink your architecture because you're going to get hacked otherwise.

#5 pifreak   Members   -  Reputation: 111

Like
0Likes
Like

Posted 22 June 2012 - 07:28 AM

The server. Like I said, it's connecting locally.
When I mentioned connecting remotely disconnecting more often, I meant running the server on my workstation ----> connect to Amazon EC2 database being remote.

I just don't get why it keeps losing connection during a query...

pi`

#6 hplus0603   Moderators   -  Reputation: 5514

Like
0Likes
Like

Posted 22 June 2012 - 03:01 PM

I just don't get why it keeps losing connection during a query...


Use WireShark and catch it in the act!

enum Bool { True, False, FileNotFound };

#7 pifreak   Members   -  Reputation: 111

Like
0Likes
Like

Posted 25 June 2012 - 10:01 AM

Use wireshark on a command line linux server? :/

#8 hplus0603   Moderators   -  Reputation: 5514

Like
0Likes
Like

Posted 25 June 2012 - 11:17 AM

Use wireshark on a command line linux server?


Use tcpdump to generate a pcap file, and then analyze with Wireshark on another box.
Or just use tcpdump in display mode.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS