Update country field in MySQL table from GeoIP country database
I have a table which records IP addresses of my visitors. This table is named crm_record
I have downloaded the Maxmind GeoIP country database and want to update the country field in crm_record from this table
I know of this query to query the maxmind database
SELECT country_name
FROM crm_geo_country
WHERE INET_ATON("82.145.208.23") BETWEEN beginip AND endip
开发者_如何学GoHowever I need the syntax for an UPDATE query which would allow me to update the country field on crm_record from crm_geo_country
UPDATE crm_record r
JOIN crm_geo_country gc
ON INET_ATON(r.address) BETWEEN gc.beginip AND gc.endip
SET r.country = gc.country_name
Note that this is going to be quite inefficient.
You need either to store your IP addresses in numeric format of modify the geoip table to use spatial fields for storing ranges.
精彩评论