Manage databases
This topic describes how to manage databases in Alibaba Cloud ApsaraDB for Milvus (Milvus). These operations are similar to those in traditional database engines. You can create multiple databases in a Milvus instance, configure fine-grained access control, and grant management permissions to specific users.
Prerequisites
The PyMilvus library is installed on your local client and is updated to the latest version.
To install or update the PyMilvus library, run the following command.
pip install --upgrade pymilvusA Milvus instance has been created. For more information, see Create a Milvus instance.
A connection to the Milvus instance has been established. The following code shows an example.
from pymilvus import connections, db conn = connections.connect( host="c-xxx.milvus.aliyuncs.com", # The public endpoint of the Milvus instance. port=19530, # The port used by the proxy. The default is 19530. user="<yourUsername>", # The username for the Milvus instance. password="<yourPassword>" # The password for the username. )
Limits
By default, a Milvus instance supports a maximum of 64 databases.
Create a database
Connect to a Milvus instance and specify a name for the database that you want to create.
database = db.create_database("<yourDbname>")<yourDbname> is the name of the database to create. This topic uses milvus_demo as an example. You can change the name as needed.
Use a database
By default, a Milvus instance includes a database named default. Unless specified otherwise, all collections are created in the default database. To switch to a different database for subsequent operations, run the following statement.
db.using_database("milvus_demo")You can also specify an existing database when you connect to Milvus.
conn = connections.connect(host="c-xxx.milvus.aliyuncs.com", port=19530, user="<yourUsername>", password="<yourPassword>", db_name="milvus_demo")List databases
Run the following command to list all databases in the Milvus instance.
db.list_database()Delete a database
Before you delete a database, you must purge all collections within it. A database that contains collections cannot be deleted.
db.drop_database("milvus_demo")References
For more information, see Manage users and roles.