首页 > 解决方案 > MySQL 5.7 -> 8 迁移:如何更改现有 MySQL 几何列的 SRID?

问题描述

我正在将一个大型数据库从 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.

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

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

标签: mysqldatabase-migrationmysql-8.0spatial-index

解决方案


推荐阅读