locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode startIpNum,endIpNum,locId gooshare.com note: had to change dmzCode into metroCode in the following query CREATE TABLE `citylocation` ( `locId` int(11) unsigned NOT NULL, `country` char(2) default NULL, `region` char(2) default NULL, `city` varchar(255) default NULL, `postalCode` varchar(8) default NULL, `latitude` float(12,7) default NULL, `longitude` float(12,7) default NULL, `metroCode` tinyint(4) unsigned default NULL, `areaCode` tinyint(4) unsigned default NULL, PRIMARY KEY (`locId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `iplocation` ( `startIpNum` int(11) unsigned NOT NULL, `endIpNum` int(11) unsigned NOT NULL, `locId` int(11) unsigned NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql LOAD DATA LOCAL INFILE 'GeoLiteCity-Location.csv' INTO TABLE citylocation FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode); $hostname='www.constantvzw.com'; $ip = gethostbyname($hostname); $out = "The following URLs are equivalent:\n"; $out .= $hostname.', http://' . $ip . '/, and http://' . sprintf("%u", ip2long($ip)) . "\n"; 1092059968 -> constantvzw.com SELECT city FROM citylocation, iplocation WHERE 1092059968 >=iplocation.startIpNum AND 1092059968 <=iplocation.endIpNum AND citylocation.locId=iplocation.locId ORDER BY city; +--------+ | city | +--------+ | Hudson | +--------+ 1 row in set (4.47 sec) SELECT city, country FROM citylocation GROUP BY city ORDER BY country, city; 123955 rows in set (17.21 sec) SELECT country FROM citylocation GROUP BY country; 248 rows in set (0.00 sec)