Import Example Database

Examples used in the TiDB manual use System Data from Capital Bikeshare, released under the Capital Bikeshare Data License Agreement.

Download all data files

The system data is available for download in .zip files organized per year. Downloading and extracting all files requires approximately 3GB of disk space. To download all files for years 2010-2017 using a bash script:

  1. mkdir -p bikeshare-data && cd bikeshare-data
  2. curl -L --remote-name-all https://s3.amazonaws.com/capitalbikeshare-data/{2010..2017}-capitalbikeshare-tripdata.zip
  3. unzip \*-tripdata.zip

Load data into TiDB

The system data can be imported into TiDB using the following schema:

  1. CREATE DATABASE bikeshare;
  2. USE bikeshare;
  3. CREATE TABLE trips (
  4. trip_id bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
  5. duration integer not null,
  6. start_date datetime,
  7. end_date datetime,
  8. start_station_number integer,
  9. start_station varchar(255),
  10. end_station_number integer,
  11. end_station varchar(255),
  12. bike_number varchar(255),
  13. member_type varchar(255)
  14. );

You can import files individually using the example LOAD DATA command here, or import all files using the bash loop below:

  1. LOAD DATA LOCAL INFILE '2017Q1-capitalbikeshare-tripdata.csv' INTO TABLE trips
  2. FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  3. LINES TERMINATED BY '\r\n'
  4. IGNORE 1 LINES
  5. (duration, start_date, end_date, start_station_number, start_station,
  6. end_station_number, end_station, bike_number, member_type);

Import all files

Import Example Database - 图1

Note

When you start the MySQL client, use the --local-infile=1 option.

To import all *.csv files into TiDB in a bash loop:

  1. for FILE in *.csv; do
  2. echo "== $FILE =="
  3. mysql bikeshare --local-infile=1 -e "LOAD DATA LOCAL INFILE '${FILE}' INTO TABLE trips FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (duration, start_date, end_date, start_station_number, start_station, end_station_number, end_station, bike_number, member_type);"
  4. done;