Here's a C++ program that reads data from a MySQL database and performs k-means clustering on the dataset. The program outputs the resulting clusters and centroids.

```cpp
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <mysql.h>

using namespace std;

struct Point {
    double x, y;
};

double euclidean_distance(const Point &a, const Point &b) {
    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

void k_means(vector<Point> &points, int k, vector<Point> &centroids, vector<int> &assignments) {
    // Initialize centroids randomly
    for (int i = 0; i < k; ++i) {
        centroids[i] = points[rand() % points.size()];
    }

    bool converged = false;
    while (!converged) {
        converged = true;

        // Assign each point to the closest centroid
        for (size_t i = 0; i < points.size(); ++i) {
            int best_centroid = -1;
            double best_distance = numeric_limits<double>::max();

            for (int j = 0; j < k; ++j) {
                double distance = euclidean_distance(points[i], centroids[j]);
                if (distance < best_distance) {
                    best_distance = distance;
                    best_centroid = j;
                }
            }

            if (assignments[i] != best_centroid) {
                assignments[i] = best_centroid;
                converged = false;
            }
        }

        // Update centroids based on new assignments
        vector<int> counts(k, 0);
        fill(centroids.begin(), centroids.end(), Point{0, 0});

        for (size_t i = 0; i < points.size(); ++i) {
            centroids[assignments[i]].x += points[i].x;
            centroids[assignments[i]].y += points[i].y;
            counts[assignments[i]]++;
        }

        for (int i = 0; i < k; ++i) {
            if (counts[i] > 0) {
                centroids[i].x /= counts[i];
                centroids[i].y /= counts[i];
            }
        }
    }
}

int main() {
    // Connect to MySQL database
    MYSQL *conn = mysql_init(NULL);
    if (!mysql_real_connect(conn, "localhost", "username", "password", "database_name", 0, NULL, 0)) {
        cerr << "Error connecting to the database: " << mysql_error(conn) << endl;
        return 1;
    }

    // Read data from the database
    vector<Point> points;

    if (mysql_query(conn, "SELECT x, y FROM table_name")) {
        cerr << "Error querying the database: " << mysql_error(conn) << endl;
        return 1;
    }

    MYSQL_RES *result = mysql_store_result(conn);
    MYSQL_ROW row;

    while ((row = mysql_fetch_row(result))) {
        Point p;
        p.x = atof(row[0]);
        p.y = atof(row[1]);
        points.push_back(p);
    }

    mysql_free_result(result);
    mysql_close(conn);

    // Perform k-means clustering
    int k = 3;
    vector<Point> centroids(k);
    vector<int> assignments(points.size());

    k_means(points, k, centroids, assignments);

    // Output resulting clusters and centroids
    cout << "Clusters:" << endl;
    for (size_t i = 0; i < points.size(); ++i) {
        cout << "(" << points[i].x << ", " << points[i].y << ") -> Cluster " << assignments[i] + 1 << endl;
    }

    cout << "\nCentroids:" << endl;
    for (int i = 0; i < k; ++i) {
        cout << "Cluster " << i + 1 << ": (" << centroids[i].x << ", " << centroids[i].y << ")" << endl;
    }

    return 0;
}
```

Make sure to replace `username`, `password`, `database_name`, and `table_name` with the appropriate values for your MySQL database. The table should have two columns named `x` and `y` containing the dataset's coordinates.

To compile this program, you'll need to link against the MySQL C API library:

```sh
g++ -o kmeans kmeans.cpp -lmysqlclient
```

You may also need to install the development package for the MySQL C API if it's not already installed on your system.
다음은 MySQL 데이터베이스에서 데이터를 읽고 데이터 세트에 대해 K-평균 클러스터링을 수행하는 C++ 프로그램입니다. 이 프로그램은 결과 클러스터와 중심을 출력합니다.

```cpp
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <mysql.h>

using namespace std;

struct Point {
    double x, y;
};

double euclidean_distance(const Point &a, const Point &b) {
    return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}

void k_means(vector<Point> &points, int k, vector<Point> &centroids, vector<int> &assignments) {
    // Initialize centroids randomly
    for (int i = 0; i < k; ++i) {
        centroids[i] = points[rand() % points.size()];
    }

    bool converged = false;
    while (!converged) {
        converged = true;

        // Assign each point to the closest centroid
        for (size_t i = 0; i < points.size(); ++i) {
            int best_centroid = -1;
            double best_distance = numeric_limits<double>::max();

            for (int j = 0; j < k; ++j) {
                double distance = euclidean_distance(points[i], centroids[j]);
                if (distance < best_distance) {
                    best_distance = distance;
                    best_centroid = j;
                }
            }

            if (assignments[i] != best_centroid) {
                assignments[i] = best_centroid;
                converged = false;
            }
        }

        // Update centroids based on new assignments
        vector<int> counts(k, 0);
        fill(centroids.begin(), centroids.end(), Point{0, 0});

        for (size_t i = 0; i < points.size(); ++i) {
            centroids[assignments[i]].x += points[i].x;
            centroids[assignments[i]].y += points[i].y;
            counts[assignments[i]]++;
        }

        for (int i = 0; i < k; ++i) {
            if (counts[i] > 0) {
                centroids[i].x /= counts[i];
                centroids[i].y /= counts[i];
            }
        }
    }
}

int main() {
    // Connect to MySQL database
    MYSQL *conn = mysql_init(NULL);
    if (!mysql_real_connect(conn, "localhost", "username", "password", "database_name", 0, NULL, 0)) {
        cerr << "Error connecting to the database: " << mysql_error(conn) << endl;
        return 1;
    }

    // Read data from the database
    vector<Point> points;

    if (mysql_query(conn, "SELECT x, y FROM table_name")) {
        cerr << "Error querying the database: " << mysql_error(conn) << endl;
        return 1;
    }

    MYSQL_RES *result = mysql_store_result(conn);
    MYSQL_ROW row;

    while ((row = mysql_fetch_row(result))) {
        Point p;
        p.x = atof(row[0]);
        p.y = atof(row[1]);
        points.push_back(p);
    }

    mysql_free_result(result);
    mysql_close(conn);

    // Perform k-means clustering
    int k = 3;
    vector<Point> centroids(k);
    vector<int> assignments(points.size());

    k_means(points, k, centroids, assignments);

    // Output resulting clusters and centroids
    cout << "Clusters:" << endl;
    for (size_t i = 0; i < points.size(); ++i) {
        cout << "(" << points[i].x << ", " << points[i].y << ") -> Cluster " << assignments[i] + 1 << endl;
    }

    cout << "\nCentroids:" << endl;
    for (int i = 0; i < k; ++i) {
        cout << "Cluster " << i + 1 << ": (" << centroids[i].x << ", " << centroids[i].y << ")" << endl;
    }

    return 0;
}
```

사용자 이름`, `비밀번호`, `데이터베이스 이름`, `테이블 이름`을 MySQL 데이터베이스에 적합한 값으로 바꾸어야 합니다. 테이블에는 데이터 세트의 좌표를 포함하는 `x` 및 `y`라는 이름의 두 개의 열이 있어야 합니다.

이 프로그램을 컴파일하려면 MySQL C API 라이브러리에 대해 링크해야 합니다:

```sh
g++ -o kmeans kmeans.cpp -lmysqlclient
```

MySQL C API용 개발 패키지가 시스템에 아직 설치되어 있지 않은 경우 이를 설치해야 할 수도 있습니다.