连接数据库

使用 Claude Code 进行软件开发

Dani Zysman

AI Curriculum Manager @ DataCamp

Chinook 数据库

recraft: half: 一个风格化的数字音乐商店,漂浮着黑胶唱片、音符和数据库图标

  • 一个数字音乐商店,包含:
    • 275 位艺术家(AC/DC、Aerosmith…)
    • 347 张专辑,3,503 首曲目
    • 客户、发票、播放列表

用 Claude 探索真实数据!

使用 Claude Code 进行软件开发

项目进展

music-analytics-api/
  app.py
  routes.py
  test_routes.py
  models.py
  chinook.db         # <- SQLite database file
  CLAUDE.md
  .claude/           # Previous Agents, Skills and Hooks

SQLite:单个文件内的自包含数据库。无需服务器配置。

使用 Claude Code 进行软件开发

能查询什么?

Chinook 数据库表与自然语言查询

使用 Claude Code 进行软件开发

连接并验证

$ claude mcp add-json sqlite '{"command": "uvx", "args": ["mcp-server-sqlite", 
"--db-path","~/chinook.db"1}'

Added stdio MCP server sqlite to local config
$ claude > /mcp
使用 Claude Code 进行软件开发

用自然语言查询

> Show me all Pink Floyd albums
Here are all the albums by Pink Floyd in the database:
Album ID: 183
Title: Dark Side Of The Moon
Artist: ID 120
There is 1 album by Pink Floyd in the database.
使用 Claude Code 进行软件开发

MCP 查询流程

流程层级:提出问题、Claude 选择 MCP 工具、MCP 服务器运行 SQL、数据库返回数据、显示结果

使用 Claude Code 进行软件开发

让我们一起练习吧!

使用 Claude Code 进行软件开发

Preparing Video For Download...