如何查找并访问Hyperledger Fabric-CA默认数据库及查询指定表
Got it, let's break down how to access the default Hyperledger Fabric CA database in your setup—since you're running the First Network, the CA uses SQLite by default (it's a lightweight, file-based database, no separate server required). Each CA node (like ca.org1.example.com or ca.org2.example.com) has its own independent database file. Here's step-by-step what you need to do:
Step 1: Connect to Your Vagrant Virtual Machine
Since your Fabric environment lives inside a Vagrant VM, start by accessing it from your Windows 7 host:
vagrant ssh
Step 2: Locate the Running CA Container
First, confirm which Fabric CA containers are active (they'll be running if you started the First Network with ./byfn.sh up):
docker ps | grep fabric-ca
You'll see output similar to this (example for Org1's CA):
abc123456789 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-serv…" 2 hours ago Up 2 hours 0.0.0.0:7054->7054/tcp ca.org1.example.com
Note down the container name (e.g., ca.org1.example.com) or ID (e.g., abc123456789).
Step 3: Enter the CA Container's Shell
Connect directly to the CA container's command line:
docker exec -it <CA_CONTAINER_NAME_OR_ID> bash
Step 4: Access the SQLite Database
The default database file is stored at /var/hyperledger/fabric-ca-server/fabric-ca-server.db. Use the built-in sqlite3 tool to connect to it:
sqlite3 /var/hyperledger/fabric-ca-server/fabric-ca-server.db
You'll see a sqlite> prompt, meaning you're successfully connected to the database.
Step 5: Query the Tables You Need
Now you can run SQL queries to pull data from the tables you're interested in:
- To view all affiliations:
SELECT * FROM affiliations; - To view all registered users:
SELECT * FROM users; - To view all issued certificates:
SELECT * FROM certificates;
Quick tips: Run .tables to list all available tables in the database, or .exit to quit the SQLite prompt when you're done.
Optional: Copy the Database File to Your Windows 7 Host
If you prefer to use a graphical tool (like SQLiteStudio) to browse the database, you can copy the file out of the container and into your Windows system:
- From the Vagrant VM shell, copy the DB file from the container to the VM's home directory:
docker cp <CA_CONTAINER_NAME_OR_ID>:/var/hyperledger/fabric-ca-server/fabric-ca-server.db . - Exit the Vagrant VM shell:
exit - Copy the file from the VM to your Windows 7 host (replace
C:\Your\Target\Folderwith your desired local path):vagrant scp default:/home/vagrant/fabric-ca-server.db C:\Your\Target\Folder - Open the
.dbfile with a SQLite GUI tool of your choice.
Important Notes
- If your CA containers aren't running, start the First Network first by navigating to the
first-networkdirectory in the Vagrant VM and running./byfn.sh up. - Each organization's CA has its own separate database—make sure you're accessing the correct CA container for the org you want to query.
内容的提问来源于stack exchange,提问作者deepak parmar

