MySQL NDB Cluster 8.1 手册
MySQL NDB Cluster 8.0 手册
NDB Cluster 内部机制手册
本示例(也可在 storage/ndb/ndbapi-examples/ndbapi_basic/ndbapi_basic_connect.cpp
中找到)演示了如何使用 Ndb_cluster_connection
使用给定的连接字符串连接到 NDB 管理服务器。如果成功,它将获取并打印有关集群的一些信息。如果无法连接到管理服务器或数据节点,它将打印相应的错误并退出。
#include <iostream>
#include <cstdlib>
#include <NdbApi.hpp>
namespace
{
inline void test_connection(const Ndb_cluster_connection &connection)
{
std::cout << "Connected to: " << connection.get_system_name()
<< ",\n\ton port: " << connection.get_connected_port()
<< ",\n\tactive NDBDs: " << connection.get_active_ndb_objects()
<< std::endl;
}
}
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cout << "Usage: ndb_ndbapi_basic_connect <connectstring>"
<< std::endl;
return EXIT_FAILURE;
}
const char *connectstring = argv[1];
ndb_init();
{
Ndb_cluster_connection connection(connectstring);
if (connection.connect() != 0)
{
std::cout << "Cannot connect to cluster management server" << std::endl;
return EXIT_FAILURE;
}
if (connection.wait_until_ready(30, 0) != 0)
{
std::cout << "Cluster was not ready within 30 secs" << std::endl;
return EXIT_FAILURE;
}
// Let's verify connection
test_connection(connection);
}
ndb_end(0);
return EXIT_SUCCESS;
}