ST_Distance(g1, g2 [, unit])

Returns the distance between g1 and g2, measured in the length unit of
the spatial reference system (SRS) of the geometry arguments, or in the
unit of the optional unit argument if that is specified.

This function processes geometry collections by returning the shortest
distance among all combinations of the components of the two geometry
arguments.

ST_Distance() handles its geometry arguments as described in the
introduction to this section, with these exceptions:

o ST_Distance() detects arguments in a geographic (ellipsoidal) spatial
  reference system and returns the geodetic distance on the ellipsoid.
  ST_Distance() supports distance calculations for geographic SRS
  arguments of all geometry types.

o If any argument is geometrically invalid, either the result is an
  undefined distance (that is, it can be any number), or an error
  occurs.

o If an intermediate or final result produces NaN or a negative number,
  an ER_GIS_INVALID_DATA
  (https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference
  .html#error_er_gis_invalid_data) error occurs.

ST_Distance() permits specifying the linear unit for the returned
distance value with an optional unit argument which ST_Distance()
handles as described in the introduction to this section.

URL: https://dev.mysql.com/doc/refman/8.4/en/spatial-relation-functions-object-shapes.html

