Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: July 27, 2025
Storing latitude and longitude data in relational databases poses some challenges due to the spatial nature of the data, as traditional numeric data types don’t lend themselves well to their related calculations.
In this article, we’ll explore some options for storing geographical coordinates (latitude/longitude) in MySQL. First, we’ll look at DECIMAL for its simplicity. Second, we’ll look at POINT, MySQL’s first-class datatype for coordinates introduced in 5.7.
Note that we won’t recommend using FLOAT or DOUBLE as they don’t carry the precision for accurate latitude/longitude calculations.
If we primarily need to store and retrieve the values and perform simple calculations, storing latitude and longitude in separate DECIMAL columns is often quite straightforward and highly recommended. It provides exact precision because it stores numbers as exact decimal values, avoiding the floating-point inaccuracies that can occur with FLOAT or DOUBLE.
This is crucial for geographical coordinates, where even tiny inaccuracies can lead to noticeable errors in distance calculations or mapping. We have control over precision and scale. Accordingly, we can specify the total number of digits (precision) and the number of digits after the decimal point (scale) to our needs.
Latitude can range from -90 to +90. Therefore, we generally need two digits before the decimal point. A common recommendation is DECIMAL(10, 8) or DECIMAL(9, 7).
Longitude can range from -180 to +180. Hence, we generally need three digits before the decimal point. A common recommendation is DECIMAL(11, 8) or DECIMAL(10, 7).
As a reminder, in DECIMAL(x, y), x is our precision, and y is our scale; x-y gives us the number of digits before the decimal point. In both cases, we can adjust the scale based on the required accuracy:
An example of using the DECIMAL type includes our general recommendations:
CREATE TABLE Coordinates (
id INT AUTO_INCREMENT PRIMARY KEY,
location VARCHAR(255),
latitude DECIMAL(10, 8) NOT NULL,
longitude DECIMAL(11, 8) NOT NULL
);
INSERT INTO Coordinates (location, latitude, longitude)
VALUES ('Eiffel Tower', 48.8584, 2.2945);
SELECT * FROM Coordinates;
+----+--------------+-------------+------------+
| id | location | latitude | longitude |
+----+--------------+-------------+------------+
| 1 | Eiffel Tower | 48.85840000 | 2.29450000 |
+----+--------------+-------------+------------+
We should use DECIMAL when:
POINT is ideal if we plan to perform more complex geospatial operations directly within MySQL. These calculations can be finding points within a certain radius, checking if a point is within a polygon, or calculating distances using built-in spatial functions.
POINT in MySQL 8.0+ is specially designed for spatial data in several ways:
An example of using the POINT type – note that ST_PointFromText expects coordinates in (longitude latitude) order, not (latitude longitude):
CREATE TABLE Locations (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
coordinates POINT NOT NULL SRID 4326,
SPATIAL INDEX(coordinates)
);
INSERT INTO Locations (name, coordinates)
VALUES ('Eiffel Tower', ST_PointFromText('POINT(2.2945 48.8584)', 4326));
INSERT INTO Locations (name, coordinates)
VALUES ('Arc de Triomphe', ST_PointFromText('POINT(2.2950 48.8738)', 4326));
We can query latitude/longitude data just like any other type of data. For example, let’s query the distance in meters between the Eiffel Tower and the Arc de Triomphe:
SELECT
ST_Distance_Sphere(t1.coordinates, t2.coordinates) AS Distance_in_Meters
FROM
Locations AS t1,
Locations AS t2
WHERE
t1.name = 'Eiffel Tower' AND t2.name = 'Arc de Triomphe';
We should get a result set that includes the distance in meters:
+--------------------+
| Distance_in_Meters |
+--------------------+
| 1711.9340400063334 |
+--------------------+
We should use POINT when:
In this article, we learned about the most suitable data types for storing latitude and longitude in a MySQL database. The two most commonly used data types are DECIMAL and POINT. There’s no single data type that’s ideal for all types of use cases. Therefore, our choice is guided by needs for precision, storage efficiency, and the types of spatial queries we plan to run.