{"id":29150267,"url":"https://github.com/humanmade/go-anonymize-mysqldump","last_synced_at":"2025-06-30T23:10:02.742Z","repository":{"id":55200905,"uuid":"215914362","full_name":"humanmade/go-anonymize-mysqldump","owner":"humanmade","description":"Allows you to pipe data from mysqldump or an SQL file and anonymize it.","archived":false,"fork":false,"pushed_at":"2022-10-07T10:11:15.000Z","size":3098,"stargazers_count":59,"open_issues_count":11,"forks_count":25,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-06-30T16:14:52.084Z","etag":null,"topics":["anonymization","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humanmade.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":"2019-10-18T01:11:41.000Z","updated_at":"2025-04-24T20:46:57.000Z","dependencies_parsed_at":"2023-01-19T13:45:32.783Z","dependency_job_id":null,"html_url":"https://github.com/humanmade/go-anonymize-mysqldump","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/humanmade/go-anonymize-mysqldump","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2Fgo-anonymize-mysqldump","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2Fgo-anonymize-mysqldump/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2Fgo-anonymize-mysqldump/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2Fgo-anonymize-mysqldump/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humanmade","download_url":"https://codeload.github.com/humanmade/go-anonymize-mysqldump/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humanmade%2Fgo-anonymize-mysqldump/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262864257,"owners_count":23376461,"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":["anonymization","sql"],"created_at":"2025-06-30T23:10:01.686Z","updated_at":"2025-06-30T23:10:02.712Z","avatar_url":"https://github.com/humanmade.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `anonymize-mysqldump`\n\n[![CircleCI](https://circleci.com/gh/humanmade/go-anonymize-mysqldump.svg?style=svg\u0026circle-token=ebedd768d31011e20aff68c78694a171e62a7ec0)](https://circleci.com/gh/humanmade/go-anonymize-mysqldump)\n\nAllows you to pipe data from `mysqldump` or an SQL file and anonymize it:\n\n```sh\nmysqldump -u yada -pbadpass -h db | anonymize-mysqldump --config config.json \u003e anonymized.sql\n```\n\n```\nusage: anonymize-mysqldump [-h|--help] -c|--config \"\u003cvalue\u003e\"\n\n                           Reads SQL from STDIN and replaces content for\n                           anonymity based on the provided config.\n\nArguments:\n\n  -h  --help    Print help information\n  -c  --config  Path to config.json\n```\n\n## Installation\n\nYou can download the binary for your system from the [Releases](https://github.com/humanmade/go-anonymize-mysqldump/releases/) page. Once downloaded and `gunzip`'d, move it to a location in your path such as `/usr/local/bin` and make it executable. For instance, to download the MacOS binary for 64 bit platforms (this is most common):\n\n```sh\nLATEST=\"0.3.0\"\ncurl -OL https://github.com/humanmade/go-anonymize-mysqldump/releases/download/$LATEST/go-anonymize-mysqldump_darwin_amd64.gz\ngunzip go-anonymize-mysqldump_darwin_amd64.gz\nmv go-anonymize-mysqldump_darwin_amd64 /usr/local/bin/anonymize-mysqldump\nchmod +x /usr/local/bin/anonymize-mysqldump\n```\n\n## Usage\n\nThis tool is designed to read a file stream over STDIN and produce an output over STDOUT. A config file is required and can be provided via the `-c` or `--config` flag. An example config for anonymizing a WordPress database is provided at [`config.example.json`](./config.example.json):\n\n```sh\ncurl -LO https://raw.githubusercontent.com/humanmade/go-anonymize-mysqldump/master/config.example.json\n```\n\nWhenever the tool experiences an error, it will output a log to STDERR. If you wish to not see that output while the command is running, redirect it to some other file (or `/dev/null` if you don't care):\n\n```sh\nmysqldump -u yada -pbadpass -h db | anonymize-mysqldump --config config.json 2\u003e path/to/errors.log \u003e anonymized.sql\n```\n\n## Caveats\n\nImportant things to be aware of!\n\n- Currently this only modifies `INSERT` statements. Should you wish to modify other fields, feel free to submit a PR.\n- **Verify the output file has been modified.** This is a friendly reminder this tool is still in its early days and you should verify the output sql file before distributing it to ensure the desired modifications have been applied.\n\n## Config File\n\nAn example config for anonymizing a WordPress database is provided at [`config.example.json`](./config.example.json).\n\nThe config is composed of many objects in the `patterns` array:\n\n- `patterns`: an array of objects defining what modifications should be made.\n  - `tableName`: the name of the table the data will be stored in (used to parse `INSERT` statements to d\tetermine if the query should be modified.)\n  - `fields`: an array of objects defining modifications to individual values' fields\n    - `field`: a string representing the name of the field. Not currently used, but still required to work and useful for debugging.\n    - `position`: the 1-based index of what number column this field represents. For instance, assuming a table with 3 columns `foo`, `bar`, and `baz`, and you wished to modify the `bar` column, this value would be `2`.\n    - `type`: a string representing the type of data stored in this field. Read more about field types [here](#field-types).\n    - `constraints`: an array of objects defining comparison rules used to determine if a value should be modified or not. Currently these are limited to a simple string equality comparison.\n      - `field`: a string representing the name of the field.\n      - `position`: the 1-based index of what number column this field represents. For instance, assuming a table with 3 columns `foo`, `bar`, and `baz`, and you wished to modify the `bar` column, this value would be `2`.\n      - `value`: string value to match against.\n\n### Constraints\n\nSupposing you have a WordPress database and you need to modify certain meta, be it user meta, post meta, or comment meta. You can use `constraints` to update data only whenever a certain condition is matched. For instance, let's say you have a user meta key `last_ip_address`. If you wanted to change that value, you can use the following config in the `fields` array:\n\n```\n{\n  \"field\": \"meta_value\",\n  \"position\": 4,\n  \"type\": \"ipv4\",\n  \"constraints\": [\n    {\n      \"field\": \"meta_key\",\n      \"position\": 3,\n      \"value\": \"last_ip_address\"\n    }\n  ]\n}\n\n```\n\n\n\n### Field Types\n\nEach column stores a certain type of data, be it a name, username, email, etc. The `type` property in the config is used to define the type of data stored, and ultimately the type of random data to be inserted into the field. [https://github.com/dmgk/faker](https://github.com/dmgk/faker) is used for generating the fake data. These are the types currently supported:\n\n- `username`\n- `password`\n- `email`\n- `url`\n- `name`\n- `firstName`\n- `lastName`\n- `paragraph`\n- `ipv4`\n\nIf you need another type, please feel free to add support and file a PR!\n\n## Credit\n\nMany thanks to [`Automattic/go-search-replace`](https://github.com/Automattic/go-search-replace) for serving as the starting point for this tool! Also many thanks to [`xwb1989/sqlparser`](https://github.com/xwb1989/sqlparser) for the SQL parsing library. I wouldn't have been able to do this without it!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanmade%2Fgo-anonymize-mysqldump","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumanmade%2Fgo-anonymize-mysqldump","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumanmade%2Fgo-anonymize-mysqldump/lists"}