Skip to content

Instantly share code, notes, and snippets.

@hzbd
Forked from gka/db-setup.sql
Created August 16, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hzbd/f1a1bb4c6ec3fe2b85779d71490fd926 to your computer and use it in GitHub Desktop.
Save hzbd/f1a1bb4c6ec3fe2b85779d71490fd926 to your computer and use it in GitHub Desktop.
load geoip database into mysql
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;
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