{"id":23786325,"url":"https://github.com/plusiv/mysql-scriptor","last_synced_at":"2026-04-13T03:03:48.719Z","repository":{"id":47599901,"uuid":"515009230","full_name":"plusiv/mysql-scriptor","owner":"plusiv","description":"Automate common scripts with MySQL without writting any command on the MySQL CLI.","archived":false,"fork":false,"pushed_at":"2022-09-20T03:10:17.000Z","size":44,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T10:45:53.993Z","etag":null,"topics":["database","database-as-a-service","database-connector","database-management","docker","docker-compose","docker-container","docker-image","dockerfile","mysql","shell","shell-script","shell-scripting"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plusiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-18T02:26:26.000Z","updated_at":"2022-10-04T01:49:01.000Z","dependencies_parsed_at":"2023-01-18T14:50:28.043Z","dependency_job_id":null,"html_url":"https://github.com/plusiv/mysql-scriptor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/plusiv/mysql-scriptor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plusiv%2Fmysql-scriptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plusiv%2Fmysql-scriptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plusiv%2Fmysql-scriptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plusiv%2Fmysql-scriptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plusiv","download_url":"https://codeload.github.com/plusiv/mysql-scriptor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plusiv%2Fmysql-scriptor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264608261,"owners_count":23636693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-as-a-service","database-connector","database-management","docker","docker-compose","docker-container","docker-image","dockerfile","mysql","shell","shell-script","shell-scripting"],"created_at":"2025-01-01T14:16:42.018Z","updated_at":"2026-04-13T03:03:43.702Z","avatar_url":"https://github.com/plusiv.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySQL Scriptor Container\r\n\r\n## Table of Contents\r\n\r\n- [About](#about)\r\n- [Getting Started](#getting_started)\r\n- [Avanced usage](#avanced_usage)\r\n- [Built Using](#built_using)\r\n- [Authors](#authors)\r\n- [Contributing](#contribuiting)\r\n\r\n## About \u003ca name = \"about\"\u003e\u003c/a\u003e\r\n\r\nThis tool helps to automate common scripts with [MySQL Containers](https://hub.docker.com/_/mysql) without writting any command on the [MySQL CLI](https://dev.mysql.com/doc/refman/8.0/en/mysql.html).\r\n\r\nSupported tasks for the moment are:\r\n- User creation (with grant privileges) and dropping.\r\n- Database creating and dropping.\r\n- Multiple `.sql` scripts execution.\r\n- Connection testing.\r\n\r\nThis tool is also util for automation and _CI/CD_ procceses since it allows run scripts on MySQL database in a faster and secure way, without connecting directly to it.\r\n\r\n## Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\r\n\r\nTo use this tool you must pull the image from [Docker Hub](https://hub.docker.com/r/jorgmassih/mysql-scriptor-container), and run the container in the **same network** as your database container, additionally you must pass the environments variables that describes what you want to achieve. \r\n\r\n```shell\r\ndocker run jorgmassih/mysql-scriptor-container \\\r\n    -e MYSQL_HOST='\u003cyour-database-host\u003e' \\\r\n    -e MYSQL_PORT='\u003cyour-database-port\u003e' \\\r\n    -e MYSQL_USER='\u003cyour-database-user\u003e' \\\r\n    -e MYSQL_PASSWORD='\u003cyour-database-password\u003e' \\\r\n    -e ACTION_DATABASE='create' \\\r\n    -e ACTION_DATABASE_NAME='testdb' \\\r\n    -e ACTION_USER='create' \\\r\n    -e ACTION_USER_NAME='test-user' \\\r\n    -e ACTION_USER_PASSWORD='P@ssw0rd' \\\r\n    -e ACTION_USER_ALLOWED_HOSTS='%' \\\r\n    -e ACTION_USER_GRANT_ALL='yes'\r\n    --network \u003cmy-database-network\u003e\r\n```\r\nThe previous command will attempt to create a database called `testdb` and also a user called `test-user` identified by the password `P@ssw0rd` allowed to be connected from everywhere (since was set with `%`) and with all grants to that databse.\r\n\r\nYou can also write that long line in a `docker-compose` file for an elegant solution.\r\n\r\n```yaml\r\n---\r\nversion: '3'\r\nservices:\r\n  msc: \r\n    image: jorgmassih/mysql-scriptor-container \r\n    container_name: mysql-client\r\n    environment:\r\n      - MYSQL_HOST=database\r\n      - MYSQL_PORT=3306\r\n      - MYSQL_USER=root\r\n      - MYSQL_PASSWORD=root\r\n      - ACTION_DATABASE=create\r\n      - ACTION_DATABASE_NAME=testdb\r\n      - ACTION_USER=create\r\n      - ACTION_USER_NAME=test-user\r\n      - ACTION_USER_PASSWORD=P@ssw0rd\r\n      - ACTION_USER_ALLOWED_HOSTS=%\r\n      - ACTION_USER_GRANT_ALL=yes\r\n    depends_on: \r\n      - mysql\r\n    networks:\r\n      - database\r\n\r\n  mysql:\r\n    image: mysql:5.7\r\n    container_name: dummy-mysql\r\n    environment:\r\n      - MYSQL_ROOT_PASSWORD=root\r\n    networks:\r\n      - database\r\n\r\n  adminer:\r\n    image: adminer\r\n    depends_on: \r\n      - mysql\r\n    ports:\r\n      - 8080:8080\r\n    networks:\r\n      - database\r\n\r\nnetworks:\r\n  database:\r\n```\r\n\r\n\u003e **Important Note**: make sure the user you are using has Privileges to Grant other users. In the above example, the user `root` were used.\r\n\r\n### Environmental Variables\r\n\r\nAvailable Environmental Variables at the moment will be listed below.\r\n\r\n**MySQL connection variables**\r\n| Variable Name              | Options                | Default | Description                |\r\n|----------------------------|------------------------|---------|----------------------------|\r\n| `MYSQL_USER`               | Any                    | root    | MySQL connection user.     |\r\n| `MYSQL_PASSWORD`           | Any                    | _N/A_   | MySQL connection password. |\r\n| `MYSQL_HOST`               | Any                    | mysql   | MySQL connection host.     |\r\n| `MYSQL_PORT`               | Any number             | 3306    | MySQL connection port.     |\r\n| `MYSQL_PROTOCOL`           | tcp,socket,pipe,memory | tcp     | MySQL connecto protocol.   |\r\n| `MYSQL_CONNECTION_TIMEOUT` | Any number             | 5       | MySQL connection timeout.  |\r\n\r\n**Actions variables**\r\n| Variable Name                 | Options               | Default               | Description                                                           |\r\n|-------------------------------|-----------------------|-----------------------|-----------------------------------------------------------------------|\r\n| `ACTION_USER`                 | create,drop           | create                | Creates or Drops user.                                                |\r\n| `ACTION_USER_NAME`            | any                   | _N/A_                 | Name of user to create or drop.                                       |\r\n| `ACTION_USER_PASSWORD `       | any                   | _N/A_                 | User password (only with `create` action)                             |\r\n| `ACTION_USER_ALLOWED_HOSTS`   | any ip direcction     | localhost             | Specify which hosts will be available to use the user.                |\r\n| `ACTION_USER_AUTH_PLUGIN`     | mysql_native_password | mysql_native_password | Authentication plugin for connection.                                 |\r\n| `ACTION_USER_GRANT_ALL_ON_DB` | yes,no                | no                    | Grants all privileges for selected database by `ACTION_DATABASE_NAME` |\r\n| `ACTION_DATABASE`             | create,drop           | create                | Creates or Drops database.                                            |\r\n| `ACTION_DATABASE_NAME`        | any                   | _N/A_                 | Name of database to create or drop.                                   |\r\n\r\n\r\n**Others variables**\r\n| Variable Name              | Options    | Default       | Description                     |\r\n|----------------------------|------------|---------------|---------------------------------|\r\n| `TEST_CONNECTION_ONLY`     | yes,no     | no            | Exits after connection testing. |\r\n\r\n\r\n## Avanced usage \u003ca name = \"avance_usage\"\u003e\u003c/a\u003e\r\n### Using a configuration file\r\n\r\nYou can specify the MySQL configuration in a file and create a bind volume to the path `/etc/mysql/my.cnf` in the container. This configuration file must have to follow the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/option-files.html) for `my.cnf` file but just with the `[client]` group.\r\n\r\n```ini\r\n# my-config.cnf\r\n[client]\r\nhost=database\r\nuser=jorgmassih\r\npassword=root\r\nport=3306\r\nprotocol=tcp\r\n```\r\nAnd inside of the `docker-compose.yml`:\r\n```yml\r\n---\r\nversion: '3'\r\nservices:\r\n  msc: \r\n    image: jorgmassih/mysql-scriptor-container \r\n    container_name: mysql-client\r\n    environment:\r\n      - ACTION_DATABASE=create\r\n      - ACTION_DATABASE_NAME=testdb\r\n      - ACTION_USER=create\r\n      - ACTION_USER_NAME=test-user\r\n      - ACTION_USER_PASSWORD=P@ssw0rd\r\n      - ACTION_USER_ALLOWED_HOSTS=%\r\n      - ACTION_USER_GRANT_ALL=yes\r\n    volumes: \r\n      - /path/to/my-config.cnf:/etc/mysql/my.cnf\r\n    networks:\r\n      - mysql-database-network\r\n```\r\n\r\nKeeping a file ready with your connection parameters allows you to run the container without keeping your credentials in your _CI/CD_ process.\r\n\r\nIf you want a more secure approach while using it manually, you can remove the credentias from your configuration file and set to `yes` the environmental variable `PROMPT_CREDENTIALS`, and then you will be prompted for connection `user` and `password`.\r\n\r\n\r\n## ⛏️ Built Using \u003ca name = \"built_using\"\u003e\u003c/a\u003e\r\n\r\n- [Purely Bash 📟](https://en.wikipedia.org/wiki/Bash_(Unix_shell))\r\n\r\n## ✍️ Authors \u003ca name = \"authors\"\u003e\u003c/a\u003e\r\n\r\n- [@jorgmassih👨‍💻](https://github.com/jorgmassih) - Idea \u0026 Initial work\r\n\r\n## 🤝 Contributing \u003ca name = \"contributing\"\u003e\u003c/a\u003e\r\nI'm open to contributions!\r\nIf you are interested in collaborating, you can reach out to me via the info on [my bio](https://github.com/Jorgmassih).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplusiv%2Fmysql-scriptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplusiv%2Fmysql-scriptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplusiv%2Fmysql-scriptor/lists"}