Created
February 13, 2013 10:40
-
-
Save gka/4943757 to your computer and use it in GitHub Desktop.
load geoip database into mysql
This file contains 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
DROP TABLE IF EXISTS location; | |
CREATE TABLE IF NOT EXISTS `location` ( | |
`locId` int(11) unsigned NOT NULL AUTO_INCREMENT, | |
`country` varchar(2) DEFAULT NULL, | |
`region` varchar(2) DEFAULT NULL, | |
`city` varchar(1000) DEFAULT NULL, | |
`postalCode` varchar(10) DEFAULT NULL, | |
`latitude` float DEFAULT NULL, | |
`longitude` float DEFAULT NULL, | |
`metroCode` int(11) DEFAULT NULL, | |
`areaCode` int(11) DEFAULT NULL, | |
PRIMARY KEY (`locId`), | |
KEY `city` (`city`(767)) | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
DROP TABLE IF EXISTS blocks; | |
CREATE TABLE `blocks` ( | |
`startIpNum` int(11) unsigned NOT NULL AUTO_INCREMENT, | |
`endIpNum` int(11) DEFAULT NULL, | |
`locId` int(11) DEFAULT NULL, | |
PRIMARY KEY (`startIpNum`) | |
) ENGINE=InnoDB AUTO_INCREMENT=3758096129 DEFAULT CHARSET=latin1; | |
This file contains 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
DATABASE=geoip | |
DB_USER=root | |
mysql -u $DB_USER $DATABASE < db-setup.sql | |
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity-latest.zip | |
unzip -j GeoLiteCity-latest.zip | |
mv GeoLiteCity-Location.csv location.csv | |
mv GeoLiteCity-Blocks.csv blocks.csv | |
mysqlimport -u $DB_USER --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local $DATABASE location.csv | |
mysqlimport -u $DB_USER --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local $DATABASE blocks.csv | |
rm GeoLiteCity-latest.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is obsolete and doesn't work.