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.
  As of MySQL 8.0.18, ST_Distance() supports distance calculations for
  geographic SRS arguments of all geometry types. Prior to MySQL
  8.0.18, the only permitted geographic argument types are Point and
  Point, or Point and MultiPoint (in any argument order). If called
  with other geometry type argument combinations in a geographic SRS,
  an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS error occurs.

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 error occurs.

As of MySQL 8.0.14, ST_Distance() permits an optional unit argument
that specifies the linear unit for the returned distance value. These
rules apply:

o If a unit is specified but not supported by MySQL, an
  ER_UNIT_NOT_FOUND error occurs.

o If a supported linear unit is specified and the SRID is 0, an
  ER_GEOMETRY_IN_UNKNOWN_LENGTH_UNIT error occurs.

o If a supported linear unit is specified and the SRID is not 0, the
  result is in that unit.

o If a unit is not specified, the result is in the unit of the SRS of
  the geometries, whether Cartesian or geographic. Currently, all MySQL
  SRSs are expressed in meters.

A unit is supported if it is found in the INFORMATION_SCHEMA
ST_UNITS_OF_MEASURE table. See
https://dev.mysql.com/doc/refman/8.0/en/st-units-of-measure-table.html.

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

