VERSICH

How to Connect MySQL to Claude AI Using MCP Server

how to connect mysql to claude ai using mcp server

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 MCPWhat It Means For You
Show all databases and tablesInstant overview of your entire database structure
Describe table structure and columnsNo need to click through your DB client manually
Query data in plain EnglishNo SQL knowledge needed just ask naturally
Count records, find totals, calculate averagesInstant aggregations without writing GROUP BY queries
Filter and search data"Show me all orders above ₹50,000 from last month"
Compare data across tablesClaude handles the JOINs automatically
Explain what is in your databaseAsk "What does the orders table contain?" and get a clear answer
Spot patterns and summarise dataClaude reads the results and gives you insights

Still Manual Claude Cannot Do This (with SELECT only)Why
Insert new records into tablesINSERT permission not granted
Update or modify existing dataUPDATE permission not granted
Delete records or drop tablesDELETE/DROP permission not granted
Create new tables or databasesCREATE permission not granted
Change database schemaALTER 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 userFor 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.

  1. Open the Claude Desktop app
  2. Click the Settings icon (gear icon, bottom-left of the window)
  3. Click the Developer tab on the left side
  4. 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)

  1. Look at the bottom-right of your screen near the clock for the Claude icon in the system tray
  2. Right-click the Claude icon → click Quit or Exit
  3. Claude Desktop is now fully closed
  4. Open Claude Desktop fresh from the Start Menu

Method B Task Manager (If you cannot find the system tray icon)

  1. Press Ctrl + Shift + Esc to open Task Manager
  2. Find Claude in the list of processes
  3. Right-click it → End task
  4. If there are multiple Claude entries, end ALL of them
  5. 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.

Frequently Asked Questions

Is the MySQL MCP server free?

Yes. The mysql-mcp-server package is open source and completely free to use. It is downloaded automatically via npx the first time Claude connects you do not need to manually install or pay for anything. The only cost is your normal Claude usage, which depends on your Anthropic plan.

Can Claude modify or delete data in my database?

Only if you grant it those permissions. If the MySQL user in your config has only SELECT permission, Claude physically cannot run INSERT, UPDATE, or DELETE queries the database will reject them with an access denied error. This is why using a read-only user is so important. As long as you follow the safety tip of granting SELECT only, your data is completely safe from accidental modification.

Can I connect multiple databases at the same time?

Yes, in two ways. If you leave MYSQL_DATABASE empty in the config, Claude has access to all databases on that server and can switch between them based on your question. If you have databases on different servers, you can add multiple mysql entries in the mcpServers config with different names (like mysql_production and mysql_analytics) pointing to different hosts. Claude will use each one based on context.