{"id":15715428,"url":"https://github.com/cloudflare/worker-template-mysql","last_synced_at":"2025-04-13T06:41:18.023Z","repository":{"id":40700668,"uuid":"424346865","full_name":"cloudflare/worker-template-mysql","owner":"cloudflare","description":"Reference demo and modified MySQL driver to connect Cloudflare Workers to a relational database.","archived":false,"fork":false,"pushed_at":"2024-09-25T03:15:47.000Z","size":546,"stargazers_count":54,"open_issues_count":7,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T11:43:29.863Z","etag":null,"topics":["cloudflare","database","mysql","serverless","sql","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-03T19:00:45.000Z","updated_at":"2025-03-14T03:10:02.000Z","dependencies_parsed_at":"2024-12-27T02:06:27.100Z","dependency_job_id":"5ce0f6be-cbdf-4e63-8105-8a794e9daabb","html_url":"https://github.com/cloudflare/worker-template-mysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/worker-template-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"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":["cloudflare","database","mysql","serverless","sql","workers"],"created_at":"2024-10-03T21:41:33.205Z","updated_at":"2025-04-13T06:41:18.001Z","avatar_url":"https://github.com/cloudflare.png","language":"JavaScript","readme":"# Cloudflare Workers + MySQL\n\nThis repo contains example code and a MySQL driver that can be used in any Workers project. If you \nare interested in using the driver _outside_ of this template, copy the `driver/mysql` module\ninto your project's `node_modules` or directly alongside your source.\n\n## Usage\n\nBefore you start, please refer to the **[official tutorial](https://developers.cloudflare.com/workers/tutorials/query-postgres-from-workers-using-database-connectors)**.\n\n```typescript\nconst mysql = new Client()\nconst mysqlClient = await mysql.connect({\n    username: '\u003cDATABASE_USER\u003e',\n    db: '\u003cDATABASE_NAME\u003e',\n    // hostname is the full URL to your pre-created Cloudflare Tunnel, see documentation here:\n    // https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/create-tunnel\n    hostname: env.TUNNEL_HOST || 'https://dev.example.com',\n    password: env.DATABASE_PASSWORD, // use a secret to store passwords\n})\n```\n\n**Please Note:**\n- you must use this config object format vs. a database connection string\n- the `hostname` property must be the URL to your Cloudflare Tunnel, _NOT_ your database host\n    - your Tunnel will be configured to connect to your database host\n\n## Running the MySQL Demo\n\n`mysql/docker-compose.yml`\n\nThis docker-compose composition will get you up and running with a local instance of `mysql` and a \ncopy of `cloudflared` to enable your applications to securely connect through an encrypted tunnel. \nUnlike the PostgreSQL example, this does not contain any server-side connection pool, but you can \nconfigure one behind `cloudflared` should it be necessary.\n\n### Usage\n\n\u003e from within `scripts/mysql`, run: \n\n1. **Create credentials file (first time only)**\n```sh\ndocker run -v ~/.cloudflared:/etc/cloudflared cloudflare/cloudflared:2021.10.5 login\n```\n\n2. **Start a local dev stack (cloudflared/mysql)**\n```sh\nTUNNEL_HOSTNAME=dev.example.com docker-compose up\n```","funding_links":[],"categories":["Templates \u0026 Examples"],"sub_categories":["Starter Templates"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fworker-template-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Fworker-template-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fworker-template-mysql/lists"}