Skip to content
MCP server
Registry

MySQL MCP Server

Query MySQL databases from AI assistants, read-only by default with opt-in writes.

MySQL scores 69 (Good), licensed MIT and written in Python. It installs as a local process. It declares 2 tools. Filed under Databases, AI and memory. GitHub shows 10 stars. Package registries report about 25 downloads a week. Install configs are generated for 12 clients. Being listed in the registry is not the same as being vendor-official.

by burakdirinMITPython10 stars
Trust score
69Good
Trust score 69 of 100, Good

Good trust

69 of 100 from six public signals. Nobody can buy a point.

  • Listed in the official MCP registry.
  • OSI-style license: mit.
How we score trust
Scorecard

License, quality and maintenance

How grades work
Trust breakdown

Where the 69 comes from

22 + 20 + 3 + 10 + 4 + 10 = 69. Each factor is capped, so no single signal can carry a listing.

Registry22 / 30

Active in the official MCP registry, plus a known vendor namespace.

Registry: 22 of 30 points.
Maintenance20 / 20

How recently the repository saw a commit or release.

Maintenance: 20 of 20 points.
Popularity3 / 20

GitHub stars and weekly downloads, on a log scale.

Popularity: 3 of 20 points.
License10 / 10

A clear, OSI-style open-source license.

License: 10 of 10 points.
Security4 / 10

Not archived, a secure install path, a pinned version.

Security: 4 of 10 points.
Docs10 / 10

A real summary, a README with depth, listed tools.

Docs: 10 of 10 points.

Install

Pick your client, copy the config, paste it in.

Needs Cursor or VS Code installed on this device. The button opens the app and asks you to confirm before it adds the server.

~/Library/Application Support/Claude/claude_desktop_config.json
{  "mcpServers": {    "burakdirin-mysqldb-mcp-server": {      "command": "uvx",      "args": [        "mysqldb-mcp-server"      ],      "env": {        "MYSQL_HOST": "",        "MYSQL_PORT": "3306",        "MYSQL_USER": "",        "MYSQL_PASSWORD": "YOUR_MYSQL_PASSWORD",        "MYSQL_DATABASE": "",        "MYSQL_SSL_MODE": "PREFERRED",        "MYSQL_SSL_CA": "",        "MYSQL_ALLOW_WRITE": "false",        "MYSQL_QUERY_TIMEOUT": "30",        "MYSQL_MAX_ROWS": "1000"      }    }  }}

Environment variables

NameRequiredNotes
MYSQL_HOSTRequiredMySQL host name or IP address.
MYSQL_PORTOptionalTCP port of the MySQL server.
MYSQL_USERRequiredUser name; use a dedicated user with SELECT and SHOW VIEW grants only.
MYSQL_PASSWORDSecretOptionalPassword of the MySQL user.
MYSQL_DATABASEOptionalDefault schema for unqualified table names.
MYSQL_SSL_MODEOptionalTLS mode, as in the mysql client: DISABLED, PREFERRED, REQUIRED, VERIFY_CA or VERIFY_IDENTITY. Defaults to VERIFY_CA when MYSQL_SSL_CA is set.
MYSQL_SSL_CAOptionalCA certificate file that VERIFY_CA and VERIFY_IDENTITY trust in addition to the system's CAs.
MYSQL_ALLOW_WRITEOptionalOffer the mysql_execute tool, which can change data and schema.
MYSQL_QUERY_TIMEOUTOptionalSeconds a call may take before its statement is stopped.
MYSQL_MAX_ROWSOptionalMost rows mysql_query returns.

Tools2Tool docs quality grade F

All capabilities

About

MySQL MCP Server

An MCP server that lets AI assistants explore and query a MySQL database. It is read-only by default: writing needs an explicit opt-in.

It uses the official MySQL Connector/Python and runs over stdio. It is tested with MySQL 8.4 and 9.7.

Tools

ToolAvailableWhat it does
mysql_queryalwaysRuns one reading statement (SELECT, WITH, TABLE, VALUES, SHOW, DESC, DESCRIBE, EXPLAIN) in a read-only transaction. Returns columns, rows, row_count, a truncated flag and MySQL's warnings.
mysql_executeonly with MYSQL_ALLOW_WRITE=trueRuns one statement that changes data or schema, with autocommit. Returns rows_affected (for a CALL, that of the procedure's last statement), last_insert_id and warnings; rows it returns are discarded.

Both tools take a single sql argument holding exactly one statement; the server disables multi-statements, so SELECT 1; DROP TABLE t is a syntax error. Every call opens its own connection, so USE, SET, user variables, temporary tables, locks and transactions do not carry over to the next call. Use schema.table names; MYSQL_DATABASE only sets the default.

A call gets MYSQL_QUERY_TIMEOUT seconds, including any wait for a free slot. At most 16 statements run at once, counting those still being stopped; a call that finds no free slot in time gets a "busy" error. At the deadline the server closes the statement's connection, waits half a second for MySQL to notice, and then kills the session, if it still exists, with KILL from a second connection, after checking that this connection reached the same server (@@server_uuid), as it may not behind a proxy. Stopping adds at most about 4 seconds; if MySQL does not answer in that time, the error says the statement may still be running. Killing only after closing matters: MySQL 8.4 and 9.7 can corrupt other clients' TLS connections when a session is killed while MySQL is blocked writing to it.

mysql_query streams rows and stops at MYSQL_MAX_ROWS rows or 24 KB of UTF-8 JSON (column names included), whichever comes first; truncated is then true. The result is returned at once, and the statement is stopped the same way as at the deadline, in the background but still holding its slot, so a statement that goes on computing after its first rows does not keep running. A call the client cancels keeps its slot until its session is over too. A response carries the rows twice, as structured content and as the same JSON in text, which keeps it well within the roughly 25,000 tokens that clients such as Claude Code accept from a tool.

When the server shuts down, whether stdin closes or it gets SIGTERM, SIGINT or SIGHUP, it refuses new calls, stops the statements still running and answers their calls, waiting at most about 6 seconds for that. A second signal exits at once, which may leave a statement running. A client that stops reading the server's output while it shuts down may get its last response cut off.

Memory is bounded: mysql_query reads at most 256 KB of column definitions and 96 KB of rows from MySQL per call, and mysql_execute at most 1 MB per row it discards, so 16 calls at once refusing 5 MB rows over TLS keep the server process around 150 MB (measured with 1,280 such calls). MySQL itself may still use a lot of memory to build large rows.

MySQL counts every connection that it accepts but that does not complete toward max_connect_errors (100 by default), and then refuses every connection from that host until FLUSH HOSTS. So when a connection cannot be made, the server opens none for 10 seconds, and then one at a time until one succeeds; calls in that time fail at once. It opens no connection to stop a statement that was never sent.

Values are JSON. DECIMAL and integers beyond 2^53 are strings, DATETIME and TIMESTAMP are written like 2024-02-29T13:14:15.123, DATE and TIME are as MySQL writes them (including zero dates and -01:30:00), JSON columns are JSON, BIT is an integer, ENUM and SET are their text (a,b), and binary strings (BINARY, VARBINARY, BLOB, GEOMETRY, VECTOR) are 0x-prefixed hex. DATETIME and TIMESTAMP carry no time zone; TIMESTAMP values are in the session's time zone, which is the server's default (@@time_zone).

Installation

You need uv. The server is started by your MCP client; there is nothing to run by hand.

Claude Code

claude mcp add mysql \
  --env MYSQL_HOST=localhost \
  --env MYSQL_USER=mcp \
  --env MYSQL_PASSWORD=your-password \
  --env MYSQL_DATABASE=shop \
  -- uvx mysqldb-mcp-server

Claude Desktop and other clients

Add this to the client's MCP configuration (for Claude Desktop, claude_desktop_config.json):

{
  "mcpServers": {
    "mysql": {
      "command": "uvx",
      "args": ["mysqldb-mcp-server"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_USER": "mcp",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "shop"
      }
    }
  }
}

Docker

docker build -t mysqldb-mcp-server .
docker run -i --rm -e MYSQL_HOST=host.docker.internal -e MYSQL_USER=mcp \
  -e MYSQL_PASSWORD=your-password mysqldb-mcp-server

Use docker run -i ... as the command of the configuration above. host.docker.internal reaches a MySQL on your machine with Docker Desktop; on Linux, also pass --add-host=host.docker.internal:host-gateway.

Configuration

The server is configured only through environment variables. It does not read .env files. Invalid values stop the server at startup with a message saying which one.

VariableDefaultDescription
MYSQL_HOSTrequiredHost name or IP address.
MYSQL_PORT3306TCP port.
MYSQL_USERrequiredUser name.
MYSQL_PASSWORDemptyPassword.
MYSQL_DATABASEnoneDefault schema for unqualified table names.
MYSQL_SSL_MODEPREFERRED, or VERIFY_CA when MYSQL_SSL_CA is setDISABLED, PREFERRED, REQUIRED, VERIFY_CA or VERIFY_IDENTITY, as in the mysql client. Use VERIFY_IDENTITY for any server reached over a network.
MYSQL_SSL_CAnoneCA certificate file that VERIFY_CA and VERIFY_IDENTITY trust in addition to the system's CAs, for example your cloud provider's bundle. Other modes refuse it.
MYSQL_ALLOW_WRITEfalseRegister the mysql_execute tool, and allow an account that may write.
MYSQL_QUERY_TIMEOUT30Seconds a call may take before its statement is stopped.
MYSQL_MAX_ROWS1000Most rows mysql_query returns.

With DISABLED, accounts using caching_sha2_password, MySQL's default, can only log in after a TLS login has cached their password on the server (it forgets after a restart or FLUSH PRIVILEGES), because Connector/Python does not do the RSA key exchange such a login needs; the error then says so. REQUIRED refuses a server without TLS before sending any credentials. The certificates MySQL generates for itself at first start do not pass verification on Python 3.13 and later, including the Docker image ("Missing Authority Key Identifier"); give the server a certificate from a proper CA to use VERIFY_CA or VERIFY_IDENTITY.

Security

The MySQL account's privileges are the real boundary: everything the account may read, the assistant can read, and query results are sent to your AI provider. Use a dedicated account with read privileges on the schemas the assistant should see and nothing else:

CREATE USER 'mcp'@'%' IDENTIFIED BY 'your-password';
GRANT SELECT, SHOW VIEW ON shop.* TO 'mcp'@'%';

Unless MYSQL_ALLOW_WRITE=true, the server enforces this: it refuses to start, and mysql_query refuses to run, if the account, with the roles active in its session, holds any privilege other than SELECT, SHOW VIEW, SHOW DATABASES, PROCESS and USAGE, or if its grants cannot be read. The check runs at startup and again on every call, so roles activated or grants added later are caught too. MySQL must therefore be reachable when the server starts. A read-only transaction alone cannot stop what a privileged account can do through a SELECT: built-in functions that change replication or InnoDB settings, and stored functions that run SET GLOBAL, work inside one.

What the server cannot check: views and routines with SQL SECURITY DEFINER (the default) run with their owner's privileges. A read-only account that may select from a view, or execute a routine, owned by a more privileged account can do through it whatever the owner allows, including changing server settings. Review such objects in the schemas you grant.

Reading has side effects worth knowing. PROCESS, or SELECT on performance_schema (which SELECT ON *.* includes), shows other sessions' statements. A long read holds metadata locks on its tables until the call ends; an ALTER TABLE on them waits for it, and queries that arrive after the ALTER wait behind it. The account needs two connections per running call, one for the statement and one to stop it, so keep max_user_connections above twice the calls you expect at once.

mysql_query adds layers on top of the account's privileges:

  • It refuses any statement that does not start with a reading keyword, any statement with an executable comment (/*! ... */), and any statement containing the words OUTFILE or DUMPFILE, even in a string.
  • It runs the statement with transaction_read_only on and inside START TRANSACTION READ ONLY, so MySQL refuses writes to tables, including WITH ... DELETE, SELECT ... FOR UPDATE and stored functions that write. Shared locking reads (FOR SHARE, LOCK IN SHARE MODE) run and hold their locks until the call ends.
  • It disables multi-statements and LOAD DATA LOCAL, and closes the connection after every call.

A statement may still load the server until the timeout stops it. Optimizer hints can lift MySQL's max_execution_time, which is why the server enforces the timeout itself.

Writing is opt-in. With MYSQL_ALLOW_WRITE=true the server skips the account check and also offers mysql_execute, which runs with all privileges of the configured account, including DROP. mysql_query then still refuses writes to tables, but functions the account may run can change the server's state, so it is no longer marked read-only. Enable writing only with an account whose privileges match what you are willing to let the assistant change, and keep your client's tool-call confirmation on. The password is only used to connect; it is never included in tool results or error messages.

Development

uv sync

The tests run against a real MySQL, with an account that has all privileges, as root does (they create a schema, a routine, roles and users). Start one, for example with Docker:

docker run -d --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=ci mysql:8.4

then point the tests at it with the same variables the server uses (the host defaults to 127.0.0.1 and the user to root):

export MYSQL_PASSWORD=ci
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run pyright

The tests of certificate verification run when MYSQL_TEST_SSL_CA names the CA that signed the server's certificate for 127.0.0.1; CI sets this up, as .github/workflows/ci.yml shows.

To release, set the new version in pyproject.toml and both places in server.json, date the CHANGELOG entry, and push a vX.Y.Z tag; the release workflow publishes to PyPI and the MCP Registry and creates the GitHub release.

License

MIT

Frequently asked questions

What is MySQL MCP Server?

Query MySQL databases from AI assistants, read-only by default with opt-in writes.

How do I install MySQL MCP Server in Claude Desktop, Cursor, or VS Code?

Pick your client in the Install section on this page and copy the generated config into the client's config file. Step-by-step guides: Claude Desktop, Cursor, and VS Code. MySQL MCP Server runs locally from the PyPI package mysqldb-mcp-server with the command uvx mysqldb-mcp-server.

Is MySQL MCP Server free and open source?

Yes. MySQL MCP Server is released under the MIT license, an OSI-approved open-source license, so you can use, modify, and self-host it under those terms.

Does MySQL MCP Server support remote (HTTP) connections?

No remote endpoint is listed for MySQL MCP Server. It runs locally on your machine over stdio, started by your MCP client.

What tools does MySQL MCP Server provide?

MySQL MCP Server provides 2 tools: mysql_execute and mysql_query. See the full tool list for descriptions and parameters.

How is MySQL MCP Server's trust score calculated?

MySQL MCP Server scores 69 out of 100 (Good). The score adds six capped public signals: registry status, maintenance, popularity, license, documentation, and security. Nobody can pay for points. Read the methodology for the full formula.

Reviews

No reviews yet

—Be the first to review

5 star0 reviews at 5 stars
4 star0 reviews at 4 stars
3 star0 reviews at 3 stars
2 star0 reviews at 2 stars
1 star0 reviews at 1 stars

No published reviews yet. Used it? Tell the next person how it went.

Add badge to your README

Paste either snippet into the repository README. The image links to this listing.

Listed on MCPpedia

Top 5 MCP servers

Daily or weekly. Confirm by email, unsubscribe any time.

How often

Manage this listing

Claim this server