Closed robbielove closed 3 weeks ago
password: process.env.MYSQL_PASS !== undefined ? process.env.MYSQL_PASS : 'root',
on line 211 in index.ts will resolve this issue
The issue with the original code:
password: process.env.MYSQL_PASS || 'root',
is that it treats an empty string ("") as falsy, so it defaults to 'root' even when MYSQL_PASS is set to an empty string. The fix:
password: process.env.MYSQL_PASS !== undefined ? process.env.MYSQL_PASS : 'root',
ensures that if MYSQL_PASS is defined (even as an empty string), it will be used as the password. If MYSQL_PASS is undefined, it falls back to 'root'. This resolves the bug where blank passwords were being replaced by 'root'.
Hi, thank you for reporting, I will work on this.
This should be fixed now with the latest version.
Describe the bug
Out of the box, it's impossible to use a MySQL user with a blank password in
@benborla29/mcp-server-mysql
without manually modifying the source code.The issue is caused by this line in
index.js
:password: process.env.MYSQL_PASS || 'root',
This incorrectly falls back to
'root'
wheneverMYSQL_PASS
is set to an empty string (""
), since"" || 'root'
resolves to'root'
in JavaScript. This means setting:MYSQL_PASS=""
...will still result in a connection attempt using the password
"root"
, leading to this error:Error: Access denied for user 'root'@'localhost' (using password: YES)
Platform
Claude Desktop (but this applies generally to any environment trying to use the MCP server with a blank MySQL password).
MCP Configuration
Additional context
This is made significantly more frustrating by the fact that MySQL connection errors are not bubbled up or logged. The process exits with code
1
, but there's no output explaining the failure unless the user manually addsconsole.error
to the MCP server source code.Expected behavior:
MYSQL_PASS
is explicitly set (even to an empty string), that value should be respected and passed directly to the MySQL connection.This took significant effort to debug due to lack of logs and poor fallback handling - would love to see this fixed.