{"id":19131276,"url":"https://github.com/bandie91/mysqlexportcsv","last_synced_at":"2026-05-19T06:05:29.296Z","repository":{"id":151061689,"uuid":"56127511","full_name":"bAndie91/mysqlexportcsv","owner":"bAndie91","description":"Export mysql data the fastest way on server side","archived":false,"fork":false,"pushed_at":"2025-01-21T06:30:55.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T23:44:12.782Z","etag":null,"topics":["csv","export","import","locking","mysql"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bAndie91.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2016-04-13T06:40:32.000Z","updated_at":"2025-01-21T06:30:58.000Z","dependencies_parsed_at":"2025-02-22T17:40:01.733Z","dependency_job_id":null,"html_url":"https://github.com/bAndie91/mysqlexportcsv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bAndie91/mysqlexportcsv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bAndie91%2Fmysqlexportcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bAndie91%2Fmysqlexportcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bAndie91%2Fmysqlexportcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bAndie91%2Fmysqlexportcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bAndie91","download_url":"https://codeload.github.com/bAndie91/mysqlexportcsv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bAndie91%2Fmysqlexportcsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33204090,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"online","status_checked_at":"2026-05-19T02:00:06.763Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["csv","export","import","locking","mysql"],"created_at":"2024-11-09T06:14:41.850Z","updated_at":"2026-05-19T06:05:29.262Z","avatar_url":"https://github.com/bAndie91.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mysqlexportcsv\nExport mysql data the fastest way on server side\n\n# Usage\n```\nUsage: mysqlexportcsv [-Fsd] [-Dupt \u003cSTR\u003e] [db1[.table1] [db2[.table2] ...]]\n Exports all tables unless db or table names are given\nFlags:\n -F, --flush   Flush all tables before lock\n -s, --struct  Export only structure\n -d, --data    Export only data\nOptions:\n -D, --DSN     DSN (eg. \"dbname=mysql;host=localhost;port=3306\")\n -u, --user    Mysql username (env: DBI_USER)\n -p, --pass    Mysql password (env: DBI_PASS)\n -t, --target  Directory to export data on server side\n```\n\n# Theory\nThis script utilizes MySQL's ``SELECT INTO OUTFILE`` capability\nto save table data into CSV files, each table of each database  into\nseparated files. One can issue the ``LOAD DATA INFILE`` in loop to\nrestore data on the same mysql instance or on other.\n\n# CSV can hold only text data. Isn't it?\nNo. MySQL properly escapes and de-escapes binary data, newlines and \nmeta chars stored in CSV.\n\n# Features\n* mysqlexportcsv saves table structures too, however\nin SQL-format and on client-side (where script runs) into\nthe working directory.\n* If no parameters are given, then all tables in all databases \nare going to be exported (except performance_schema and mysql.%_log).\n* If a parameter does not include a dot, then it treated as a database\nand all of its tables are going to be exported.\n\n# Restore data example\n```\nUSE dbname;\nDROP TABLE IF EXISTS tname;\nsource dbname.tname.struct.sql;\nLOAD DATA INFILE 'dbname.tname.data.csv'\n  INTO TABLE tname\n  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"' ESCAPED BY '\\\\'\n  LINES TERMINATED BY '\\n';\n```\n\n# Caveats\n\n## File modes\nBy default, mysqlexportcsv asks mysql to export data directly in \nmysql's data directory. You can override it, but mysql daemon's\nuser must can write the target directory and also, exported \nfiles will be **world-writable** - this is how mysql works internally.\nIt does not mean information leak in common environments, due to\nmysql's data directory is not accessible by others. You may\ncreate the custom target directory by ``install -d /path/to/mysql/export \n-o mysql -m 0700``.\n\n## Locking and atomic operation\nIt uses ``LOCK TABLES READ`` to ensure data consistency. But it is still\npossible to miss one or more tables from exporting when a table is\ncreated between enumerating tables and locking them.\nUse ``--flush`` flag when tables created or dropped frequently. With it,\nmysqlexportcsv issues ``FLUSH TABLES WITH READ LOCK`` which locks\nglobally, so table and database names can be enumerated comfortably.\nThe only drawback of ``--flush`` is the unneccessary I/O.\n\n# Project issues, bugs, feature requests, ideas\n\n1. clone the repo\n2. use [git-bug](https://github.com/git-bug/git-bug) to open a new ticket in this repo\n3. find one or more person in the commit history to make contact with, then either\n4.a. send your newly created `git-bug` ticket (or patch if you already propose a code change) via email, or\n4.b. send the URL of your git clone to a contributor (via email or other channel), and request them to pull (`git-bug` issues and/or branches as well) from you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandie91%2Fmysqlexportcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbandie91%2Fmysqlexportcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbandie91%2Fmysqlexportcsv/lists"}