I have a table of approx 10,000 - 20,000 dynamic points across the globe stored as lon/lat points. I want to cluster any point within (roughly) 3km of any other point into one point (and return the averaged center point of each cluster if possible). Unlike some other solutions I have seen, I do not just want points within 3km of the central cluster point, it is fine to have a point within each cluster many kilometres away from the central cluster point as long as there is a chain of points within 3km of each other joining the points together into a single chain/cluster.
The only way I can think of doing this is looping over every point, finding any other points within 3km of that point, and then recursively each of those points etc until i find all in that perticular chain/cluster, and then repeat for all the remaining un-clustered points - this would result in millions of calculations. Is there an easier way of doing this? Preferably with MYSQL 5.6 geospatial abilities, but im open to any viable solution.