Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Monday, July 20, 2009

converting IP address to IP number

Ip number is a numerical representation of the ip address we are all used to .
For instance 1.2.3.4 = 1690960 ;

It is good for some reasons, like conveting the Ip address to geographical position, or rule manupulation like firewalls and network devices.

How do you do that ?

Here is a little method that shows how to do that in c #

public static uint convertIP(string sIp)
{
string[] sOctecs;
char[] cSeperator = { '.' };
int[] iOctet = new int[4];
uint iReturnIPNumber = 0;
if (sIp != "")
{
bool bConvertOK;
sOctecs = sIp.Split(cSeperator, 4);//split the string to the octets
for (int i = 0; i <>
{
bConvertOK = int.TryParse(sOctecs[i], out iOctet[i]);
if (!bConvertOK)
{
return 0;
}
}//end for
// iOctecs contain integers , lets do the magic

//some math
iReturnIPNumber = (uint)iOctet[3];
iReturnIPNumber = iReturnIPNumber + ((uint)iOctet[2] * (uint)256);
iReturnIPNumber = iReturnIPNumber + ((uint)iOctet[1] * (uint)256 * (uint)256);
iReturnIPNumber = iReturnIPNumber + ((uint)iOctet[0] * (uint)256 * (uint)256 * (uint)256);

}
return iReturnIPNumber;
}


If you need it in the database , then mySQL has a built in functions of converting

mysql> SELECT INET_ATON('192.168.10.50');
+----------------------------+
| INET_ATON('192.168.10.50') |
+----------------------------+
| 3232238130 |
+----------------------------+
1 row in set (0.00 sec)

mysql> SELECT INET_NTOA(839559360);
+----------------------+
| INET_NTOA(839559360) |
+----------------------+
| 50.10.168.192 |
+----------------------+
1 row in set (0.00 sec)

Tuesday, July 7, 2009

Copying Microsoft SQL table to MySQL


Performing and Performing once again; today, we need much quicker database access than we currently have: we have some Windows servers contacting with the sql database using Microsoft's SQLClient driver for accessing it.

The idea was to cache some frequently used data on the servers in the in memory databases. The problem was copying the tables' schema from the sql server to the mysql without doing in manually. So:

I wanted to recommend the Michael Kofler software . I used the gui versions and had only one problem : they both require the correct MySQL ODBC driver. I used the last version located at http://dev.mysql.com/downloads/connector/odbc/3.51.html#winx64 and nothing worked , because the MySql server version installed was not 64 bit (what a pitty ) therefore, reinstalling the Windows MSI Installer (x86) version solved the issue and the table had been copyed in notime

Thanks Micael

MySQL Memory Table Size

If you're doing some Real Time processing with MySQL, you probably better use a Memory table and only eventually commit the results to a disk table.

But if you do that with the default setting, you'll soon run out of memory on a 16MB table!!

Don't worry, it is configurable!
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_max_heap_table_size
(Note: this refers to MySQL 5.1 version, you may have another version. Also see page for other system configuration options)

And to make a long story short, open MySQL Administrator --> Health --> System Variables --> Memory --> max_heap_table_size
and set it to 268435456 (=256MB)

Thursday, February 12, 2009

Hibernate: Log SQL Statements

It's very useful when debbuging Hiberante based system to be aware of the SQL output that is being sent to the database (like the old phrase Garbage In Garbage Out)
There are two methods to do that:
1. Enable hiberante logging
2. Enable the RDBMS log files, for example: Enable MySQL SQL logging