MySQL 5.7 -> 8 迁移:如何更改现有 MySQL 几何列的 SRID?

问题描述 投票:0回答:1

我正在将一个大型数据库从 MySQL 5.7 迁移到 8。它包含几何列和空间索引。这是一个实时系统,因此迁移的停机时间是一个问题。

MySQL 8 会忽略空间索引,除非列具有 SRID。 此处的建议是重新定义列以具有显式 SRID 属性并重新创建 SPATIAL 索引。

我正在尝试这样做,但遇到了先有鸡还是先有蛋的情况:

mysql>  UPDATE noticeboards SET position = ST_SRID(position, 4236);
ERROR 3643 (HY000): The SRID of the geometry does not match the SRID
of the column 'position'. The SRID of the geometry is 4236, but the
SRID of the column is 0. Consider changing the SRID of the geometry or
the SRID property of the column.

好的,我会尝试一下:

mysql> ALTER TABLE noticeboards MODIFY position Geometry NOT NULL SRID 4326;
ERROR 3643 (HY000): The SRID of the geometry does not match the SRID of the column 
'position'. The SRID of the geometry is 0, but the SRID of the column is 4326. 
Consider changing the SRID of the geometry or the SRID property of the column.

如果我截断表,那么我可以执行更改 - 但其中一些表具有外键,因此截断是一个可怕的前景。

我是否缺少一种将现有数据从 5.7 默认 SRID 0 强制转换为另一个值的方法?

mysql database-migration mysql-8.0 spatial-index
1个回答
0
投票

使用所需的 SRID 创建一个新列,然后将 SRID 0 数据复制到其中。删除 SRID 0 列并重命名新列以匹配原始列名称。您还需要在此过程中解决任何限制

© www.soinside.com 2019 - 2024. All rights reserved.