Keep MySQL SRID 4326 Coordinates in a Consistent Axis Order

MySQL follows the axis definitions of a spatial reference system. For SRID 4326, that can conflict with applications that write coordinates as longitude first and latitude second. State the input and output axis order explicitly, then read geographic points with longitude and latitude functions instead of assuming that X always means longitude.

Last updated: November 20, 2026.

SET @p = ST_GeomFromText(
  'POINT(-73.9857 40.7484)',
  4326,
  'axis-order=long-lat'
);

SELECT
  ST_Longitude(@p) AS longitude,
  ST_Latitude(@p) AS latitude,
  ST_AsText(@p, 'axis-order=long-lat') AS longitude_latitude_wkt;

The application-facing WKT remains longitude-latitude, while the geometry retains SRID 4326. Use the same convention at every import, edit and export boundary rather than swapping values in one screen only.

Why the coordinates appear reversed

MySQL documents that ST_X() and ST_Y() follow the first and second axes of the SRS. In EPSG 4326, the first axis is latitude and the second is longitude. A tool that displays SRS-defined order can therefore look reversed beside a form that assumes the common longitude-latitude GeoJSON convention.

A current phpMyAdmin report shows this mismatch during editing with MySQL 8.0.41 and phpMyAdmin 5.2.2. Treat that report as a version-specific reproduction, not proof that every phpMyAdmin release changes data in the same way.

Use one convention at every boundary

MySQL geometry conversion functions accept an axis-order option: long-lat, lat-long or the default srid-defined. Specify the option when the external format has a known convention. The WKT constructor documentation applies the same rule when creating geometry values.

Use ST_Longitude() and ST_Latitude() when the business meaning is geographic. Before changing existing rows, inspect control points whose real locations are known. Do not run a mass coordinate swap merely because one editor shows a different order: some rows may already follow the SRS while others may have been imported as longitude-latitude.

For an import job, test one known location and compare the numeric longitude, latitude, SRID and exported WKT before processing the full file. Keep that assertion in the import test suite so a library or administration-tool upgrade cannot silently change the convention.

Related Web Cheat Sheet guides

Sergey Kornilov

Sergey Kornilov