Back up a table with a GEOMETRY column using mysqldump?

前端 未结 4 445
误落风尘
误落风尘 2021-01-12 21:22

I recently created a MySQL table with a column of type GEOMETRY.

When I back up the table with mysqldump, it outputs my geometry column as a quoted string, containin

相关标签:
4条回答
  • 2021-01-12 21:45

    Frank, this appears to be a long-standing (and still open) bug with mysqldump. See http://bugs.mysql.com/bug.php?id=43544.

    As a workaround, you may be able to use the ogr2ogr tool to export the data to a shapefile, and then import it back into the database. See http://www.bostongis.com/PrinterFriendly.aspx?content_name=ogr_cheatsheet

    0 讨论(0)
  • 2021-01-12 21:49

    I once faced this issue but manage to passthrough by using gzip. Please check my sample commands: Export:

    mysqldump -u root -p db_name | gzip > dump.sql.gz
    

    Import:

    pv dump.sql.gz | gunzip | mysql -u root -p other_db
    
    0 讨论(0)
  • 2021-01-12 22:01

    I can confirm that this problem doesn't occur when using the Export / Import Data functions in MySQL Workbench. http://www.mysql.com/products/workbench/

    0 讨论(0)
  • 2021-01-12 22:04

    In my case, this error appeared specifically with empty geometry values in a non-null geometry column.

    In my case, the empty geometries were legitimate cases of unknown geometry, so I addressed this by changing the column to allow null values, and then running UPDATE ... SET geom = NULL WHERE IsEmpty(geom);

    After this, I was able to re-run mysqldump and successfully import the resulting sql into a separate database.

    (To be honest, I'm not sure how the empty geometry values got there in the first place - I don't even know the syntax to create an empty geometry value)

    0 讨论(0)
提交回复
热议问题