Created
March 8, 2013 17:16
-
-
Save iwek/5118100 to your computer and use it in GitHub Desktop.
Importing MaxMind GeoIP Lite CSV file into MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql -u root -p root; | |
USE maxmind; | |
DROP TABLE IF EXISTS `blocks`; | |
CREATE TABLE `blocks` ( | |
`startIPNum` int(10) unsigned NOT NULL, | |
`endIPNum` int(10) unsigned NOT NULL, | |
`locID` int(10) unsigned NOT NULL, | |
PRIMARY KEY (`startIPNum`,`endIPNum`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=1 DELAY_KEY_WRITE=1; | |
DROP TABLE IF EXISTS `location`; | |
CREATE TABLE `location` ( | |
`locID` int(10) unsigned NOT NULL, | |
`country` char(2) default NULL, | |
`region` char(2) default NULL, | |
`city` varchar(45) default NULL, | |
`postalCode` char(7) default NULL, | |
`latitude` double default NULL, | |
`longitude` double default NULL, | |
`dmaCode` char(3) default NULL, | |
`areaCode` char(3) default NULL, | |
PRIMARY KEY (`locID`), | |
KEY `Index_Country` (`country`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED; | |
load data infile 'GeoLiteCity-Blocks.csv' into table `blocks` fields terminated by ',' optionally enclosed by '"' lines terminated by '\n' ignore 2 lines; | |
load data infile 'GeoLiteCity-Location.csv' into table `location` fields terminated by ',' optionally enclosed by '"' lines terminated by '\n' ignore 2 lines; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mostly taken from http://www.atomodo.com/code/how-to-really-import-the-maxmind-geoip-free-country-csv-file-into-mysql