xvp
ScribblingsDevblogs01 / Building

Effortless MySQL with AI: Introducing lazy-mysql-wizard

A Python database viewer that turns natural language into SQL, with room to review before you run.

On this page

Managing databases can be tedious especially if you don’t want to memorize SQL syntax or risk making mistakes with complex queries. So I finally built something to tidily interface with my databases: lazy-mysql-wizard, a modern Python Tkinter application that makes MySQL database management easy, safe, and even a little bit magical, thanks to GPT-4.1 AI integration.

I had made a little CLI app that turns prompt to SQL query / command, but decided it could stand on its own if I injected more context about the database, and made a formal UI. So I did!

I wouldn't completely trust it, but it will always ask if you want to run the query before doing so.

Key Features

  • AI MySQL Assistant: Ask natural language questions, and the AI will generate, review, and (with your approval) run SQL queries. It understands your schema and can chain together complex operations.
  • Modern GUI: Clean, flat, and responsive interface with dark mode, section borders, and a results table.
  • SQL Editor & History: Edit, review, and run SQL queries. Browse your query history with up/down arrows.
  • Results Viewer: View, select, and copy table results. Highlight and preview cell values.
  • AI Chat: Natural language chat with the AI, which can plan, reason, and execute database operations on your behalf.
  • Safety First: The AI only asks for confirmation before running data-changing queries (INSERT, UPDATE, DELETE). SELECT queries and safe operations are run automatically.
  • Customizable: Edit queries before running, and view all AI-generated SQL before execution.
  • No API Key Required: AI features are optional; you can use the app as a lightweight DB viewer without OpenAI integration.

How to Set Up

  1. Install dependencies:

    bash
    pip install -r requirements.txt
  2. Configure your database connection:

    Set your DB credentials in a .env file or directly in the script:

    javascript
    DB_HOST=your-db-host
    DB_USER=your-db-user
    DB_PASSWORD=your-db-password
    DB_NAME=your-db-name
    DB_PORT=3306
    OPENAI_API_KEY=your-openai-api-key
  3. Run the app:

    bash
    python db_viewer_gui.py

Keyboard Shortcuts

  • Ctrl+D: Toggle light/dark mode
  • Ctrl+Enter: Run query (when in SQL editor)
  • Ctrl+Shift+Enter: Use AI to generate a query from your prompt
  • Up/Down: Browse previous SQL commands

Why Use lazy-mysql-wizard?

  • No need to memorize MySQL syntax or best practices
  • Get expert-level SQL help instantly
  • Edit, review, and run queries safely
  • Modern, user-friendly interface
  • Optional AI features—works as a classic DB viewer too

Happy programming!

Thanks for following along.

Back to the notebook