将geonames.org数据库中的数据导入MySQL DB

Lui*_*aca 13 mysql geonames

有人如何将geonames.org数据导入我的数据库?我试图导入的是http://download.geonames.org/export/dump/DO.zip,我的数据库是MySQL数据库.

wil*_*e01 23

我通过查看链接到的zip文件中包含的自述文件在"主要'GeoName'表中包含以下字段找到了以下内容:"

首先在MySQL实例上创建数据库和表.字段的类型在我刚刚引用上面标题的部分的每一行中给出.

CREATE DATABASE DO_test;
CREATE TABLE `DO_test`.`DO_table` (
  `geonameid` INT,
  `name` varchar(200),
  `asciiname` varchar(200),
  `alternatenames` varchar(5000),
  `latitude` DECIMAL(10,7),
  `longitude` DECIMAL(10,7),
  `feature class` char(1),
  `feature code` varchar(10),
  `country code` char(2),
  `cc2` char(60),
  `admin1 code` varchar(20),
  `admin2 code` varchar(80),
  `admin3 code` varchar(20),
  `admin4 code` varchar(20),
  `population` bigint,
  `elevation` INT,
  `gtopo30` INT,
  `timezone` varchar(100),
  `modification date` date
)
CHARACTER SET utf8;
Run Code Online (Sandbox Code Playgroud)

创建表后,您可以从文件中导入数据.这些字段由制表符分隔,行作为换行符:

LOAD DATA INFILE '/path/to/your/file/DO.txt' INTO TABLE `DO_test`.`DO_table`;
Run Code Online (Sandbox Code Playgroud)


小智 15

我最近制作了一个shell脚本,它从geonames站点下载最新数据并将它们导入MySQL数据库.它基于GeoNames论坛的知识,为我节省了大量时间.

它是第一个版本,但功能齐全.也许它可以帮助.

您可以访问http://codigofuerte.github.com/GeoNames-MySQL-DataImport/


Ali*_*lix 8

对于未来的每一个人:在2008年的geonames.org论坛上,这是"将所有地理名称转储到MySQL中" http://forum.geonames.org/gforum/posts/list/732.page

另外谷歌这个:导入转储到[postgresql OR SQL server OR MySQL]网站:forum.geonames.org

甚至从2006年开始寻找更多答案

编辑提供概要:

在geoname官方读到我:http://download.geonames.org/export/dump/.我们将找到关于转储文件及其内容的良好描述.

转储文件将直接导入MySQL数据表.例如 :

SET character_set_database=utf8;
LOAD DATA INFILE '/home/data/countryInfo.txt' INTO TABLE _geo_countries IGNORE 51 LINES(ISO2,ISO3,ISO_Numeric,FIPSCode,AsciiName,Capital,Area_SqKm,Population,ContinentCode,TLD,CurrencyCode,CurrencyName,PhoneCodes,PostalCodeFormats,PostalCodeRegex,Languages,GeonameID,Neighbours,EquivalentFIPSCodes);
SET character_set_database=default;
Run Code Online (Sandbox Code Playgroud)

请注意字符集,因为如果我们使用2012年旧的phpmyadmin的CSV LOAD DATA准备导入器,即使列的排序规则设置为utf8_general_ci,我们也可能会丢失utf字符

目前有4个基本数据表:大陆,国家(countryInfo.txt),部门(admin1),城市或地点(地理名称)

admin1,2,3,4转储文件是国家内部部门的不同级别,例如admin 1,即美国或其他国家/地区的省份.admin 2更详细,是州或省的内部部门.对于3和4等等

已列出的国家/地区转储文件不仅包含城市,还包含该国家/地区的所有地理位置,甚至包括商店中心.还有一个巨大的文件,因为从zip文件中提取后,"allCountries.txt"将超过1GB.如果我们只想要城市,我们应该选择一个转储文件:cities1000.txt,cities5000.txt,cities15000.txt,这些数字代表所列城市的最小人口数.我们将城市存储在geonames datatable中(您可以将其称为地理位置或地理城市).

在导入*.txt转储文件之前,请先对MySQL文档中的LOAD DATA语法进行一些研究.

自述文本文件(也在转储页面的页脚中)提供了足够的描述,例如:

The main 'geoname' table has the following fields :
---------------------------------------------------
geonameid         : integer id of record in geonames database
name              : name of geographical point (utf8) varchar(200)
asciiname         : name of geographical point in plain ascii characters, varchar(200)
alternatenames    : alternatenames, comma separated varchar(5000)
latitude          : latitude in decimal degrees (wgs84)
longitude         : longitude in decimal degrees (wgs84)
feature class     : see http://www.geonames.org/export/codes.html, char(1)
feature code      : see http://www.geonames.org/export/codes.html, varchar(10)
country code      : ISO-3166 2-letter country code, 2 characters
cc2               : alternate country codes, comma separated, ISO-3166 2-letter country code, 60 characters
admin1 code       : fipscode (subject to change to iso code), see exceptions below, see file admin1Codes.txt for display names of this code; varchar(20)
admin2 code       : code for the second administrative division, a county in the US, see file admin2Codes.txt; varchar(80) 
admin3 code       : code for third level administrative division, varchar(20)
admin4 code       : code for fourth level administrative division, varchar(20)
population        : bigint (8 byte int) 
elevation         : in meters, integer
dem               : digital elevation model, srtm3 or gtopo30, average elevation of 3''x3'' (ca 90mx90m) or 30''x30'' (ca 900mx900m) area in meters, integer. srtm processed by cgiar/ciat.
timezone          : the timezone id (see file timeZone.txt) varchar(40)
modification date : date of last modification in yyyy-MM-dd format
Run Code Online (Sandbox Code Playgroud)

关于varchar(5000),我们应该知道MySQL 5.0或更高版本中每行的64kb大小:在MySQL中 是否有一个VARCHAR(20000)有效?