Sign inSign up

vv0lll/mysql-shell

By vv0lll

•Updated about 1 year ago

Image
Developer tools
Databases & storage
0

130

vv0lll/mysql-shell repository overview

⁠MySQL Shell Docker Container

⁠Overview

This Docker container provides a pre-configured MySQL Shell environment for interacting with MySQL databases. The container is built on Oracle Linux 9 Slim and includes the latest MySQL Shell tools for database administration, scripting, and management tasks.

⁠Features

  • MySQL Shell 8.0: Latest MySQL Shell with support for SQL, JavaScript, and Python scripting
  • Oracle Linux 9 Slim: Lightweight base image for optimal performance
  • Connection Management: Built-in connection validation and retry logic
  • Script Execution: Support for both MySQL Shell scripts and SQL scripts
  • Environment-based Configuration: Flexible configuration through environment variables

⁠Quick Start

⁠Basic Usage
⁠Interactive MySQL Shell Session
docker run -it --rm \
  -e MYSQL_HOST=localhost \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=admin \
  -e MYSQL_PASSWORD=your_password \
  vv0lll/mysql-shell
⁠Execute SQL Script
docker run --rm \
  -e MYSQL_HOST=localhost \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=admin \
  -e MYSQL_PASSWORD=your_password \
  -e MYSQL_SCRIPT=/scripts/setup.sql \
  -v /path/to/scripts:/scripts \
  vv0lll/mysql-shell mysqlsh
⁠Execute MySQL Shell Script
docker run --rm \
  -e MYSQL_HOST=localhost \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=admin \
  -e MYSQL_PASSWORD=your_password \
  -e MYSQLSH_SCRIPT=/scripts/admin.js \
  -v /path/to/scripts:/scripts \
  vv0lll/mysql-shell mysqlsh

⁠Environment Variables

⁠Required Variables
VariableDescriptionExample
MYSQL_HOSTMySQL server hostname or IP addressmysql1, 192.168.1.100
MYSQL_PORTMySQL server port3306
MYSQL_USERMySQL username for authenticationadmin, root
MYSQL_PASSWORDMySQL password for authenticationyour_secure_password
⁠Optional Variables
VariableDescriptionExample
MYSQL_SCRIPTPath to SQL script file to execute/scripts/schema.sql
MYSQLSH_SCRIPTPath to MySQL Shell script file to execute/scripts/setup.js

⁠Connection Behavior

The container includes intelligent connection handling:

  1. Connection Validation: Automatically validates database connectivity before executing commands
  2. Retry Logic: Attempts connection up to 12 times with exponential backoff
  3. Timeout Handling: Gracefully handles connection timeouts and failures
  4. Error Recovery: Continues execution even if scripts encounter errors (using || true)
⁠Common Use Cases
⁠Database Schema Setup
docker run --rm \
  --network vv0lll_default \
  -e MYSQL_HOST=mysql1 \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=${DB_MYSQL_ROOT_PASSWORD} \
  -e MYSQL_SCRIPT=/data/0x1115.sql \
  -v ./data:/data \
  vv0lll/mysql-shell mysqlsh
⁠Cluster Administration
docker run -it --rm \
  --network vv0lll_default \
  -e MYSQL_HOST=mysql1 \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=${DB_MYSQL_ROOT_PASSWORD} \
  vv0lll/mysql-shell mysqlsh

Then in the MySQL Shell:

// Check cluster status
dba.getCluster().status()

// Add instance to cluster
dba.getCluster().addInstance('mysql2:3306')

⁠Security Considerations

  • Password Security: Never hardcode passwords in scripts or environment files
  • Network Isolation: Use Docker networks to isolate database traffic
  • User Privileges: Create dedicated users with minimal required privileges
  • SSL/TLS: Enable SSL connections for production environments

⁠Troubleshooting

⁠Connection Issues
  1. Verify network connectivity:

    docker run --rm --network vv0lll_default alpine ping mysql1
    
  2. Check MySQL server logs:

    docker logs mysql1
    
  3. Validate credentials:

    # Test with mysql client
    docker run -it --rm mysql:8.0 mysql -h mysql1 -u root -p
    
⁠Script Execution Issues
  • File permissions: Ensure script files are readable inside the container
  • File paths: Use absolute paths for mounted volumes
  • Syntax errors: Validate SQL/JavaScript syntax before execution

⁠Development

⁠Running Tests
# Test basic connectivity
docker run --rm \
  --network vv0lll_default \
  -e MYSQL_HOST=mysql1 \
  -e MYSQL_PORT=3306 \
  -e MYSQL_USER=root \
  -e MYSQL_PASSWORD=test123 \
  vv0lll/mysql-shell mysqlsh --sql -e "SELECT VERSION();"
⁠Custom Scripts

Place your scripts in the project's appropriate directories:

  • SQL scripts: ./data/
  • MySQL Shell scripts: ./scripts/mysql-cluster/

⁠License

Copyright 2025 vv0lll [email protected]⁠

Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

⁠Support

For issues and questions related to this MySQL Shell container, please refer to:

  • MySQL Shell official documentation
  • Container logs for troubleshooting

Tag summary

Content type

Image

Digest

sha256:cffdea7bb…

Size

399.8 MB

Last updated

about 1 year ago

docker pull vv0lll/mysql-shell:8.0