One of the inevitable early steps in the development of any location-aware app is linking location in the form of latitude and longitude to a city, state, and country. This short tutorial will describe the few steps needed to import MaxMind’s World Cities database into a table in your own MySQL database. These steps assume you have command-line access to your MySQL server.
Get the Data
Be sure to read MaxMind’s specifications about the content and use of their data. Then, download the latest file and extract it:
Connect to your database server and get the table structure ready.
$ mysql -h localhost -u dbuser -pdbpass myappdatabase
$ mysql -h localhost -u dbuser -pdbpass myappdatabase
Depending on the application, it may make sense to index additional columns than the statement below.
mysql>CREATETABLE cities (
country CHAR(2),
city_ascii VARCHAR(100),
city VARCHAR(255),
region CHAR(2),
population INTUNSIGNED,
latitude DECIMAL(10,6),
longitude DECIMAL(10,6),INDEX idx_lat_long (latitude, longitude),INDEX idx_country (country),INDEX idx_region (region));
mysql>
CREATE TABLE cities (
country CHAR(2),
city_ascii VARCHAR(100),
city VARCHAR(255),
region CHAR(2),
population INT UNSIGNED,
latitude DECIMAL(10, 6),
longitude DECIMAL(10, 6),
INDEX idx_lat_long (latitude, longitude),
INDEX idx_country (country),
INDEX idx_region (region)
);
mysql>LOADDATALOCALINFILE'worldcitiespop.txt'INTOTABLE cities
FIELDSTERMINATEDBY','OPTIONALLYENCLOSEDBY'"'LINESTERMINATEDBY'\n'IGNORE1LINES(country, city_ascii, city, region, population, latitude, longitude);
mysql>
LOAD DATA LOCAL INFILE 'worldcitiespop.txt' INTO TABLE cities
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(country, city_ascii, city, region, population, latitude, longitude);
Now sit back and wait… At the time of this writing, the database has over 3.1 million rows. On a local windows-based development laptop it took about 8 minutes, but under a minute on a dedicated database server. This could vary depending on available system resources.
That’s it!
When the command completes the data will be ready to use. Interestingly enough, MaxMind’s page references a similar free database from GeoNames. After a brief look at the documentation, it looks like there’s a lot more data that could be useful.
Comments Off on Importing MaxMind’s World Cities Data to MySQL
CAPTCHAs are a necessary evil. These days there is no lower time-investment trade-off that works as well to prevent automated submissions to comment sections, user registration, and contact forms. That being said, they are not without issues. Read the rest of this entry »
This past winter I purchased a PF50R Honda Amigo moped. I quickly learned that this vehicle is relatively rare in America. While I was able to find parts and service manuals, most of the reference materials and parts websites are in Dutch. It seems this model is very popular in Holland and Belgium (where mine was manufactured.)
Perhaps it wouldn’t be fair to call it hibernating, given the mild winter.
The Iditarod is still winding down and I have a ton on my plate for the coming months, but for the first time in many months I have time to think about the road ahead.
It’s not like I have the wildest plans: scooter/moped/bicycle repair and riding are definitely in the plan. A number of other projects, personal and professional have been waiting for March to arrive and can now get some attention.
inSSIDer is a handy free tool for surveying wireless access points around you. Similar to Wifi Analyzer on the Android, this tool displays signal strength and channel usage graphs for all hotspots in the area. Use it to find the channel with the least interference, identify conflicting SSIDs, or just learn more about network hardware in your area.
This app is free and open source under an Apache license and is available for Windows and Linux.
Comments Off on Free Wifi Diagnostic Tool: inSSIDer