Physical oceanography models rely heavily on grid discretization. It is known that unstructured grids perform well in dealing with boundary fitting problems in complex nearshore regions. However, it is time-consuming to find a set of unstructured grids in specific ocean areas, particularly in the case of land areas that are frequently changed by human construction. In this work, an attempt was made to use machine learning for the optimization of the unstructured triangular meshes formed with Delaunay triangulation in the global ocean field, so that the triangles in the triangular mesh were closer to equilateral triangles, the long, narrow triangles in the triangular mesh were reduced, and the mesh quality was improved. Specifically, we used Delaunay triangulation to generate the unstructured grid, and then developed a K-means clustering-based algorithm to optimize the unstructured grid. With the proposed method, unstructured meshes were generated and optimized for global oceans, small sea areas, and the South China Sea estuary to carry out data experiments. The results suggested that the proportion of triangles with a triangle shape factor greater than 0.7 amounted to 77.80%, 79.78%, and 79.78%, respectively, in the unstructured mesh. Meanwhile, the proportion of long, narrow triangles in the unstructured mesh was decreased to 8.99%, 3.46%, and 4.12%, respectively.