The MySQL MCP server can be configured using a MySQL connection URL passed as a command-line argument or via specific environment variables. If no configuration is provided, the server will exit with an error.
Using a Connection URL
Pass a mysql:// URL as the first command-line argument:
mysql://user:password@host:port/database
Using Environment Variables
If no command-line argument is provided, the server falls back to these environment variables:
MYSQL_HOSTMYSQL_USERMYSQL_PASSWORDMYSQL_DATABASEMYSQL_PORT (defaults to 3306 if not set)
Using the connect_db tool
You can also change or establish a connection dynamically during a session using the connect_db tool, which accepts either a url or individual connection parameters (host, user, password, database, port).
# Example using command line argument
node index.js mysql://root:secret@localhost:3306/my_database
# Example using environment variables
export MYSQL_HOST=localhost
export MYSQL_USER=root
export MYSQL_PASSWORD=secret
export MYSQL_DATABASE=my_database
node index.js