How can I import GTFS files into MySQL?

2.5k views Asked by At

GTFS is a common format for public transportation schedules.

The General Transit Feed Specification (GTFS) defines a common format for public transportation schedules and associated geographic information. GTFS "feeds" allow public transit agencies to publish their transit data and developers to write applications that consume that data in an interoperable way.

Now, I have a trace in GTFS format, including several .txt files (tables). How can I import it into MySQL?

1

There are 1 answers

0
SparkAndShine On BEST ANSWER

With the help of @Shotgun Ninja, @Satya, I make it. Here is what I do.

cat load.sql | mysql -p -u root 

load.sql is based on github/sbma44/py-gtfs-mysql, here. The main code is as follows:

CREATE DATABASE IF NOT EXISTS gtfs;
USE gtfs

DROP TABLE IF EXISTS agency;
-- agency_id,agency_name,agency_url,agency_timezone,agency_phone,agency_lang
CREATE TABLE `agency` (
    agency_id INT(20) PRIMARY KEY,
    agency_name VARCHAR(255),
    agency_url VARCHAR(255),
    agency_timezone VARCHAR(50),
    agency_phone VARCHAR(255),
    agency_lang VARCHAR(50)
);

LOAD DATA LOCAL INFILE 'agency.txt' INTO TABLE agency FIELDS TERMINATED BY ',' IGNORE 1 LINES;

I share it on GitHub: tisseo_toulouse_gtfs.