How to Connect MySQL to Claude AI Using MCP Server
Querying a MySQL database usually means writing SQL, opening a database client, running commands, and staring at raw tables. What if you could just ask Claude in plain English "How many orders came in this month?" and get the answer instantly, straight from your live database? That is exactly what MCP makes possible. Here is the complete setup guide.
What is MCP and Why Does It Matter?
MCP stands for Model Context Protocol. It is a connection layer that allows Claude to talk directly to your MySQL database. Without MCP, Claude is just a text assistant sitting in a separate window. You ask it about your data, it gives you a SQL query, and then you manually open a database tool, paste the query, run it, and read the results. It works but it is slow and tedious.
Think of it this way
Claude is a very smart analyst sitting in one room. Your MySQL database is in another room. MCP is the direct phone line between them. Once connected, Claude can call your database and say "Show me total revenue by region" and it queries your actual data instantly and replies in plain English. Without MCP, you are the middleman ask Claude for SQL, switch to your DB tool, run it, read the output, go back to Claude, repeat.
The MySQL MCP server is an open-source package that runs locally on your computer. It is free, lightweight, and requires no coding to set up. The entire setup takes less than 10 minutes.
What Claude Can and Cannot Do Through MCP
This is the most important thing to understand before you start. MCP gives Claude access to read your database. The split depends on what permissions you have granted your database user and for safety, read-only is always the right choice.
| Claude Can Do Via MCP | What It Means For You |
| Show all databases and tables | Instant overview of your entire database structure |
| Describe table structure and columns | No need to click through your DB client manually |
| Query data in plain English | No SQL knowledge needed just ask naturally |
| Count records, find totals, calculate averages | Instant aggregations without writing GROUP BY queries |
| Filter and search data | "Show me all orders above ₹50,000 from last month" |
| Compare data across tables | Claude handles the JOINs automatically |
| Explain what is in your database | Ask "What does the orders table contain?" and get a clear answer |
| Spot patterns and summarise data | Claude reads the results and gives you insights |
| Still Manual Claude Cannot Do This (with SELECT only) | Why |
| Insert new records into tables | INSERT permission not granted |
| Update or modify existing data | UPDATE permission not granted |
| Delete records or drop tables | DELETE/DROP permission not granted |
| Create new tables or databases | CREATE permission not granted |
| Change database schema | ALTER permission not granted |
What You Need Before Starting
Claude Desktop you already have. The only things needed are Node.js on your machine and your MySQL database credentials.
- Claude Desktop App : The desktop version, not the browser. If you have only been using Claude in your browser, download the app from claude.ai/download before continuing.
- Node.js: The MySQL MCP server runs on Node.js. Download it from nodejs.org and install the LTS version. Once installed, you will also have npx available automatically no separate install needed.
- MySQL Database: Running locally or on a remote server like AWS EC2. You need the host IP, port (usually 3306), username, and password.
- A read-only MySQL user: For safety, create a user with SELECT-only permission on your database. This ensures Claude can read data but cannot accidentally modify or delete anything.
Node.js brings npx for free
When you install Node.js, npm and npx are automatically installed alongside it. You do not need to install them separately. The MCP server is run using npx which downloads and runs the mysql-mcp-server package on demand no manual installation of the MCP package is required.
The Step-by-Step Setup Process
Step 1 : Verify Node.js is Installed
Before touching the Claude config, confirm Node.js is on your machine. Open Command Prompt on Windows (search for cmd in the Start Menu) or Terminal on Mac, and run these three commands:
node --version
npm --version
npx --version
If you see version numbers for all three (like v20.11.0), you are ready to continue. If you get an error saying the command is not recognised, download and install Node.js from nodejs.org pick the LTS version. Restart your computer after installing, then run the commands again to confirm.
Step 2 : Open the Claude Desktop Config File
Claude Desktop uses a JSON config file to know which MCP servers to connect to. The easiest way to open it is directly from inside Claude Desktop no need to navigate any folders.
- Open the Claude Desktop app
- Click the Settings icon (gear icon, bottom-left of the window)
- Click the Developer tab on the left side
- Click the Edit Config button the config file opens directly
Step 3 : Add the MySQL MCP Configuration
This is the most important step. You are telling Claude Desktop where your MySQL database is and how to connect to it. Replace everything in the file with the config below filling in your actual database credentials.
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": ["-y", "mysql-mcp-server"],
"env": {
"MYSQL_HOST": "your-database-host-ip",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_mysql_username",
"MYSQL_PASSWORD": "your_mysql_password",
"MYSQL_DATABASE": ""
}
}
}
}
Replace these three values with your actual credentials
your-database-host-ip → your MySQL server IP address.
your_mysql_username → the MySQL user you created.
your_mysql_password → that user's password.
Leaving MYSQL_DATABASE empty gives Claude access to all databases on the server dynamically Claude will pick the right one based on your question.
Save the file Ctrl + S on Windows, Cmd + S on Mac.
Step 4 : Restart Claude Desktop Properly
This is where most people get stuck. Simply closing the Claude window is NOT enough Claude keeps running in the background even when the window is closed.
Method A System Tray (Recommended)
- Look at the bottom-right of your screen near the clock for the Claude icon in the system tray
- Right-click the Claude icon → click Quit or Exit
- Claude Desktop is now fully closed
- Open Claude Desktop fresh from the Start Menu
Method B Task Manager (If you cannot find the system tray icon)
- Press Ctrl + Shift + Esc to open Task Manager
- Find Claude in the list of processes
- Right-click it → End task
- If there are multiple Claude entries, end ALL of them
- Now open Claude Desktop fresh from the Start Menu
Do not just close the window
Clicking the X on the Claude Desktop window does not actually quit the app. Claude keeps running silently in the background. If you do not fully quit and restart using one of the methods above, the config changes will not take effect and the MCP server will not load.
Step 5 : Verify the Connection
Look at the Claude Desktop chat input area the box where you type messages. You should see a small hammer icon or tools icon near the input box.
The hammer or tools icon means MCP servers are connected and ready. If you do not see any icon, the setup did not work correctly check the troubleshooting section below before continuing.
The first run downloads the MCP package automatically
The first time Claude connects, npx will download the mysql-mcp-server package from the internet. This takes about 10 to 20 seconds. You will not see any visible progress just wait a moment before typing your first command. Subsequent connections are instant.
Once the hammer icon appears, type this in Claude Desktop to confirm the connection:
Show me all databases available
Safety Tips Before You Start Using It
- Always use a read-only MySQL user. Grant only SELECT permission never give Claude's connection user INSERT, UPDATE, DELETE, or DROP permissions. This is the single most important thing to get right. If something goes wrong or Claude misunderstands a request, a read-only user cannot cause any damage.
- Restrict EC2 port 3306 to your IP only. Never open it to 0.0.0.0/0. Update the Security Group rule whenever your IP changes. Exposing port 3306 to the internet is one of the most common causes of database breaches.
- Do not commit your config file to Git. The claude_desktop_config.json file contains your database password in plain text. Add it to your .gitignore immediately if you work in a repository. Never share this file or paste its contents in public channels or support tickets.
- Start with read commands before anything else. Run "Show me all databases" and "Show me all tables" first to confirm the connection is stable and Claude is reading the right database before asking more complex questions.
