Skip to Content

How Do I Connect Claude to My MySQL Server for Easy Database Management?

Can I Really Talk to My MySQL Database? A Guide to Using Natural Language for SQL Tasks

You can talk to your computer in plain English. It understands you. This is happening more and more. Now, you can even talk to your database. You don’t need to know special computer languages. This guide will show you how. We will focus on something called a MySQL MCP server.

Can I Really Talk to My MySQL Database? A Guide to Using Natural Language for SQL Tasks

Think of it like this: you have a smart helper. This helper is an AI, like Anthropic’s Claude. You want this helper to do things with your data. Your data is stored in a MySQL database. Usually, to get information from a database, you need to write code. This code is in a language called SQL. But what if you don’t know SQL? That’s where the Model Context Protocol (MCP) comes in.

MCP is like a universal translator. It lets your AI helper talk to your database. You speak or type in English. The AI and MCP work together to turn your words into SQL code. They send this code to the database. The database gives back the information. Then, the AI and MCP translate that information back into English for you. It’s a smooth conversation.

In this guide, we’ll set up a special tool. It’s called the MCP Database Server. This is an open-source tool, which means it’s free to use and modify. It acts as the bridge between your AI and your database. It can work with different kinds of databases, like SQLite, SQL Server, and PostgreSQL. But today, we’ll focus on MySQL. By the end of this, you’ll be able to manage your MySQL database just by talking to your AI. No SQL commands needed.

What You’ll Need Before You Start

The MCP Database Server is a local server. This is different from a remote server. A local server runs on your own computer. A remote server runs on a computer somewhere else. Because it’s a local server, you need to install it on the same machine where your AI application is running.

Before we get started, let’s make sure you have a few things ready. Think of this as gathering your ingredients before you start cooking. Here’s what you need to have installed on your computer:

  • Node.js: This is a program that lets you run JavaScript code outside of a web browser. It’s the environment where our MCP server will live. You’ll need version 18 or a newer one.
  • MySQL Server: This is your database. It’s where all your data is stored. Make sure you have version 5.7 or higher.
  • Git: This is a tool that helps you copy code from the internet. We’ll use it to get the MCP Database Server files.
  • An AI App: You need a smart helper that can use MCP. A great example is Claude Desktop. This is the application we’ll be connecting to our database.

Once you have these four things installed and ready to go, we can begin setting up the MCP Database Server.

Installing the MCP Database Server

Now it’s time to install the main tool, the MCP Database Server. You have two ways to do this. You can use a tool called npm, or you can use Git to clone the project’s repository.

If you want a quick and easy installation, npm is the way to go. If you’re a developer and you might want to change the code or see how it works, then using Git is the better choice. Let’s look at both options.

Option 1: The Quick Way with npm

  1. Open your computer’s terminal. This is a program that lets you type commands.
  2. Type the following command and press Enter:
    npm install -g @executeautomation/database-server

That’s it. The npm tool will download and install the MCP Database Server for you. The -g part of the command means it will be installed globally, so you can use it from anywhere on your computer.

Option 2: The Developer Way with Git

If you want more control, or if you’re curious about the code, follow these steps:

  1. Open your terminal.
  2. Use Git to make a copy of the project’s code on your computer. Type this command and press Enter:
    git clone https://github.com/executeautomation/mcp-database-server.git
  3. Now, move into the new folder that was just created. Type:
    cd mcp-database-server
  4. Next, you need to install all the other little pieces of code that the server depends on. Type:
    npm install
  5. Finally, you need to build the project. This turns the code into a program that can be run. Type:
    npm run build

Now the server is ready. You can run it from a file located at dist/src/index.js.

Starting the MCP Server

With the installation complete, the next step is to start the server. When you start it, you also need to tell it how to connect to your MySQL database.

In my example, the MySQL server is running on my own computer. That’s why I’ll use an IP address of 127.0.0.1, which means “this computer.” If your MySQL server is on a different machine, you’ll need to use that machine’s IP address instead.

Open your terminal and run the following command. Make sure to replace “StrongPasswordHere” with your actual MySQL root password.

node dist/src/index.js --mysql --host 127.0.0.1 --database mysql --port 3306 --user root --password StrongPasswordHere

Let’s quickly break down what this command does:

  • node dist/src/index.js: This tells your computer to run the server.
  • –mysql: This tells the server you want to connect to a MySQL database.
  • –host 127.0.0.1: This is the address of your MySQL server.
  • –database mysql: This specifies the name of the database to connect to.
  • –port 3306: This is the port number that MySQL uses to listen for connections.
  • –user root: This is the username for your MySQL server.
  • –password StrongPasswordHere: This is the password for that user.

After you press Enter, the MCP server will start and connect to your MySQL database.

Setting Up Claude Desktop

Your MCP server is running. Now, you need to tell your AI helper, Claude Desktop, where to find it. This is done by editing a configuration file.

  1. Open the Claude Desktop app.
  2. Go to the settings menu.
  3. Click on the “Developer” section.
  4. Find the option that says “Edit Config” and click it.

This will open a file named claude_desktop_config.json. The location of this file depends on your operating system:

  • On a Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
  • On Windows: %APPDATA%\Claude\claude_desktop_config.json
  • On Linux: ~/.config/Claude/claude_desktop_config.json

Open this file with a text editor. You’re going to add a small piece of code to it. This code tells Claude how to start and talk to your MCP server.

In the file, find the mcpServers section. Add the following JSON code inside it.

{
"mcpServers": {
"mysql": {
"command": "npx",
"args": [
"-y",
"@executeautomation/database-server",
"--mysql",
"--host", "localhost",
"--database", "mysql",
"--port", "3306",
"--user", "root",
"--password", "StrongPasswordHere"
]
}
}
}

Remember to replace “StrongPasswordHere” with your real MySQL password.

Save the file and then restart the Claude Desktop app. When it starts up again, it will know how to use your new MCP server.

Making Sure Everything Works

After you’ve done all the setup, you want to be sure it’s all working correctly.

  1. In the Claude Desktop app, go back to the “Developer” settings.
  2. You should now see “MySQL” in the list of servers, and its status should say “running.” This means Claude has successfully connected to your MCP server.
  3. Next, you need to enable the tools for the AI. In the main Claude chat window, look for a tools icon. Click on it.
  4. You’ll see a list of tools that the AI can now use. These tools are the actions it can perform on your MySQL server.

If you see the running status and the list of tools, congratulations! Your setup is complete.

Talking to Your MySQL Database

Now for the fun part. You can start having a conversation with your database. You don’t need to write any SQL. Just type what you want to know in plain English.

The AI will take your English question, figure out the right SQL command, and send it to the MCP server. The MCP server passes it to the MySQL server. The database runs the command and sends the result back. The AI then takes that result and explains it to you in a natural way.

Let’s try a few examples.

List All Users

You can ask Claude to show you all the users in your MySQL database. Just type:

“List all users”

The AI will translate this into an SQL query, something like SELECT user, host FROM mysql.user;. It will then show you a table of all the usernames and their host origins. You can see how Claude Sonnet turned a simple prompt into a real SQL command.

Check a User’s Permissions

You can ask more complex questions. For example, you might want to know what a specific user is allowed to do. Try a prompt like this:

“Check the privileges for the ‘root’@’localhost’ user.”

Claude will generate a more complicated SQL command to get this information and then present it to you in an easy-to-understand format.

Add a New User

You can even make changes to the database. Let’s try adding a new user. This is a “write” action, which means it changes data. For safety, Claude will ask for your permission before it does anything.

Try this prompt:

“Add a new user named ‘newuser’ with the password ‘aVerySecurePassword’.”

A pop-up will appear asking you to confirm that you want to run this command. Once you grant permission, the AI will execute the query, and the new user will be created.

Conclusion

You’ve done it. You have successfully connected your AI assistant to your MySQL database. You can now manage your server using everyday language. You can ask questions, get information, and even make changes, all without writing a single line of SQL code. This powerful setup opens up a new way of interacting with your data, making database management more accessible and intuitive than ever before. You are no longer limited by your knowledge of specific command languages. Instead, you can focus on what you want to achieve, and let the AI handle the technical details.