id: manage_connection.md related_key: connect Milvus

summary: Learn how to connect to a Milvus server.

管理Milvus连接

当前主题介绍怎么连接、断开 Milvus 服务器。

在进行其他操作前确保连接到 Milvus 服务器。

下面的例子使用 localhost 作为主机名,端口号 19530 展示连接或断开连接到 Milvus 服务器。

连接到 Milvus 服务器

构建一个 Milvus 连接。在进行其他操作前确保已连接 Milvus 服务。

{{fragments/multiple_code.md}}

  1. # Run `python3` in your terminal to operate in the Python interactive mode.
  2. from pymilvus import connections
  3. connections.connect(
  4. alias="default",
  5. host='localhost',
  6. port='19530'
  7. )
  1. import { MilvusClient } from "@zilliz/milvus2-sdk-node";
  2. const address = "localhost:19530";
  3. const milvusClient = new MilvusClient(address);
  1. milvusClient, err := client.NewGrpcClient(
  2. context.Background(), // ctx
  3. "localhost:19530", // addr
  4. )
  5. if err != nil {
  6. log.Fatal("failed to connect to Milvus:", err.Error())
  7. }
  1. final MilvusServiceClient milvusClient = new MilvusServiceClient(
  2. ConnectParam.newBuilder()
  3. .withHost("localhost")
  4. .withPort(19530)
  5. .build());
  1. connect -h localhost -p 19530 -a default
参数 描述
alias 创建的Milvus连接的别名。
host Milvus 服务 IP 地址。
port Milvus 服务端口号。
参数 描述
address Milvus 连接地址。
参数 描述
ctx 控制调用 API 的 context。
addr Milvus 连接地址。
参数 描述
Host Milvus IP 地址。
Port Milvus 端口。
选项 全称 描述
-h —host (可选) Milvus 服务 IP 地址。默认为 “127.0.0.1”。
-p —port (可选) Milvus 服务端口。默认为 “19530”。
-a —alias (可选) Milvus 连接别名。默认为 “default”。
-D —disconnect (可选) 使用别名断开连接的标记。默认别名为 “default”.
—help n/a 显示命令行帮助

断开 MIlvus 连接

从 MIlvus 服务器断开。

{{fragments/multiple_code.md}}

  1. connections.disconnect("default")
  1. await milvusClient.closeConnection();
  1. milvusClient.Close()
  1. milvusClient.close()
  1. connect -D
参数 描述
alias Milvus 服务别名。

使用限制

最大连接数为 65536。

更多内容

链接 Milvus 后,还可以:

关于其他操作,参考