July 14, 2010 | Posted in:Uncategorized

I recently was interested in getting some shapefile information quickly into a MySQL database. It seems like it should be a relatively simple task but you never know until you try, right? Well, thanks to the wonderful GDAL there is a great command that should be shared with the world:

ogr2ogr -f "MySQL" MySQL:"geospatial,user=user,host=localhost,password=password" -lco engine=MYISAM shapes.shp

It’s a thing of beauty! One little command line entry will take the entire contents of the shape file and push it into a MySQL database with the geometry. The only catch that I have run into so far was needing to increase a setting for increasing the MySQL allowed packet size. To change that just edit the /etc/my.inf file to include something like:


Works like a dream.

1 Comment

  1. mmln
    April 8, 2015

    did u create the mysql database and table before ? or this command automatically creates table and with all columns based on shape file.

    In your command ‘geospatial’ is it DB name or table name ?

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>