Skip to content

Conversation

@echarrod
Copy link
Contributor

@echarrod echarrod commented Nov 5, 2025

Summary

Implements support for MYSQL_CONNECTION_STRING environment variable as an alternative to individual connection parameters. This addresses Issue #35 and is particularly useful for organizations with rotating credentials that expire frequently (e.g., hourly).

Changes

Core Implementation

  • Connection String Parser (src/utils/index.ts):

    • Parses MySQL CLI-format connection strings
    • Supports short flags (-h, -P, -u, -p, -S) and long options (--host, --port, etc.)
    • Handles quoted values and complex passwords
    • Validates port numbers (1-65535 range, NaN checks)
  • Configuration Integration (src/config/index.ts):

    • Added MYSQL_CONNECTION_STRING environment variable support
    • Connection string takes precedence over individual env vars
    • Maintains backward compatibility with existing configurations
    • Fixed password fallback consistency in authPlugins

Documentation

  • Updated README.md with connection string option (positioned as alternative, not primary method)
  • Added examples and security notes about not storing in version control
  • Updated .env.dist with connection string example

Code Quality

  • All CodeRabbit review suggestions addressed
  • Port validation with proper error handling
  • Quote handling fixed to strip delimiters from values
  • Password fallback consistency between main config and authPlugins

Testing

Tested with sample connection string:

mysql --default-auth=mysql_native_password -A -hrdsproxy.staging.luno.com -P3306 -uUSER -pPASS database_name

Successfully parses all connection parameters including complex usernames and passwords.

Use Cases

This feature is particularly valuable for:

  • Rotating credentials that expire after a set time period (e.g., 1 hour)
  • Temporary database connections for testing
  • Quick configuration changes without updating multiple environment variables
  • Integration with credential management systems that provide full connection strings

Future Considerations

For credentials that expire, users may want to:

  1. Use environment variables that can be refreshed externally
  2. Create wrapper scripts that prompt for connection strings
  3. Integrate with credential management tools

Fixes #35

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Implements support for MYSQL_CONNECTION_STRING environment variable as an alternative to individual connection parameters. This is particularly useful for rotating credentials that expire frequently.

Features:
- Parse MySQL CLI-format connection strings
- Connection string takes precedence over individual env vars
- Support for -h/-P/-u/-p flags and long-form options
- Handles quoted values and complex passwords
- Documented as optional alternative in README

Addresses benborla#35

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@echarrod echarrod force-pushed the feature/mysql-connection-string-support branch from 12fa664 to c809b59 Compare November 5, 2025 10:57
@echarrod echarrod changed the title Add MySQL connection string support (Issue #35) feat: Add MySQL connection string support (Issue #35) Nov 5, 2025
@echarrod echarrod marked this pull request as ready for review November 5, 2025 11:11
@benborla benborla merged commit b0a4a61 into benborla:main Nov 18, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow connection string to be passed as arg instead of HOST + PORT + USER + PASS + DB

2 participants