access9 / dbtabledump
数据库表导出工具
0.15.0
2024-07-20 19:01 UTC
Requires
- php: >=8.1
- doctrine/dbal: ^3.5
- symfony/config: ^5.0|^6.0
- symfony/console: ^5.0|^6.0
- symfony/yaml: ^5.0|^6.0
Requires (Dev)
- ext-pdo_sqlite: *
- ext-reflection: *
- friendsofphp/php-cs-fixer: ^3.0
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^9.6
README
DbTableDump - 数据库表导出工具
DbTableDump 是一个 PHP CLI 工具,可以将数据库表导出到多种格式。
安装
先决条件
DbTableDump 需要 PHP 8.1 或更高版本。还需要数据库后端 - 支持的数据库驱动程序请见此处。
某些 Linux 发行版要求您单独安装 JSON 和/或 DOM 扩展。
Composer(直接安装)
通过 composer 安装此工具是最简单的方法
composer require access9/dbtabledump
Composer(通过您的 composer.json 文件安装)
请将以下内容添加到您的 composer.json 文件中
"access9/dbtabledump": "*"
完成两种 composer 安装方法之一后,您可以使用以下命令运行 dbtabledump:
vendor/bin/dump
克隆
当然,您始终可以克隆仓库
git clone https://github.com/bglover/dbtabledump.git
请确保使用 composer 获取所需的供应商依赖项
composer update -o
- 如果您不需要开发依赖项,建议添加
--prefer-dist
。
支持的格式
- YAML
- JSON
- 分隔符(您可以选择分隔符)
- XML
用法
dump help Usage: [options] command [arguments] Options: --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. Available commands: help Displays help for a command list Lists commands config config:get Get a configuration value. If no options are given, the entire config is printed. config:set Set a configuration value. to to:delimited Dump one or more database tables to a delimited format. to:json Dump one or more database tables to json format. to:xml Dump one or more database tables to xml. to:yaml Dump one or more database tables to yaml format.
将表导出到 YAML
dump help to:yaml Usage: to:yaml [-l|--limit="..."] [-w|--where="..."] [-u|--user="..."] [-p|--password="..."] [-o|--host="..."] [-n|--dbname="..."] tables1 ... [tablesN] Arguments: tables Space delimited list of tables to dump. Options: --limit (-l) Number of rows to limit the output to. This option applies to all tables dumped. --where (-w) Add a where clause to the sql. Clause must be in quotes: -w "name = 'larry'". --user (-u) Optional username. Overrides the user setting in config.yml --password (-p) Optional password. Overrides the password setting in config.yml --host (-o) Optional host. Overrides the host setting in config.yml --dbname (-n) Optional database name. Overrides the dbname setting in config.yml --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output.
将表导出到 JSON
dump help to:json Usage: to:json [-l|--limit="..."] [-w|--where="..."] [-u|--user="..."] [-p|--password="..."] [-o|--host="..."] [-n|--dbname="..."] [-b|--bitmask[="..."]] tables1 ... [tablesN] Arguments: tables Space delimited list of tables to dump. Options: --limit (-l) Number of rows to limit the output to. This option applies to all tables dumped. --where (-w) Add a where clause to the sql. Clause must be in quotes: -w "name = 'larry'". --user (-u) Optional username. Overrides the user setting in config.yml --password (-p) Optional password. Overrides the password setting in config.yml --host (-o) Optional host. Overrides the host setting in config.yml --dbname (-n) Optional database name. Overrides the dbname setting in config.yml --bitmask (-b) Bitmask to use. May be one or more of JSON_* constants Usage example: `dump to:json -b JSON_PRETTY_PRINT -b JSON_UNESCAPED_SLASHES table` (multiple values allowed) --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. Help: Available JSON constants are: JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT and JSON_UNESCAPED_UNICODE. See https://php.ac.cn/manual/en/json.constants.php for more information about what these do.
将表导出到分隔符格式
dump help to:delimited Usage: to:delimited [-l|--limit="..."] [-w|--where="..."] [-u|--user="..."] [-p|--password="..."] [-o|--host="..."] [-n|--dbname="..."] [-d|--delimiter="..."] [-q|--quote] tables1 ... [tablesN] Arguments: tables Space delimited list of tables to dump. Options: --limit (-l) Number of rows to limit the output to. This option applies to all tables dumped. --where (-w) Add a where clause to the sql. Clause must be in quotes: -w "name = 'larry'". --user (-u) Optional username. Overrides the user setting in config.yml --password (-p) Optional password. Overrides the password setting in config.yml --host (-o) Optional host. Overrides the host setting in config.yml --dbname (-n) Optional database name. Overrides the dbname setting in config.yml --delimiter (-d) Required delimiter to use. Enclose delimiter in quotes. --delimiter "|" --quote (-q) Quote each delimited column: '"column_one","column_two"', etc --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. Help: The --delimiter option is required. You can use tabs as your delimiter by passing "\t" as the delimiter.
将表导出到 XML
dump help to:xml Usage: to:xml [-l|--limit="..."] [-w|--where="..."] [-u|--user="..."] [-p|--password="..."] [-o|--host="..."] [-n|--dbname="..."] tables1 ... [tablesN] Arguments: tables Space delimited list of tables to dump. Options: --limit (-l) Number of rows to limit the output to. This option applies to all tables dumped. --where (-w) Add a where clause to the sql. Clause must be in quotes: -w "name = 'larry'". --user (-u) Optional username. Overrides the user setting in config.yml --password (-p) Optional password. Overrides the password setting in config.yml --host (-o) Optional host. Overrides the host setting in config.yml --dbname (-n) Optional database name. Overrides the dbname setting in config.yml --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. Help: Column names that contain spaces will have the spaces converted to underscores.
配置
初始化您的配置
dump help config:set Usage: config:set [-u|--user="..."] [-p|--password="..."] [-o|--host="..."] [-n|--dbname="..."] [-d|--driver="..."] Options: --user (-u) Username used to connect to the database. --password (-p) Password used to connect to the database. --host (-o) Host the database is on. Either an IP address or a hostname are valid. --dbname (-n) Name of the database used for dump operations. --driver (-d) Driver used to connect to the database. Valid options are pdo_mysql, drizzle_pdo_mysql, mysqli, pdo_sqlite, pdo_pgsql, pdo_oci, pdo_sqlsrv, sqlsrv, oci8 and sqlanywhere. --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output.
检索您的配置选项。
dump help config:get Usage: config:get [-u|--user] [-p|--password] [-o|--host] [-n|--dbname] [-d|--driver] Options: --user (-u) --password (-p) --host (-o) --dbname (-n) --driver (-d) --help (-h) Display this help message. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. Help: If no options are given, the entire config is printed.
支持的数据库驱动程序
本项目使用Doctrine 的 DBAL。
以下驱动程序由 Doctrine 的 DBAL 支持
- pdo_mysql
- drizzle_pdo_mysql
- mysqli
- pdo_sqlite
- pdo_pgsql
- pdo_oci
- pdo_sqlsrv
- sqlsrv
- oci8
- sqlanywhere
pdo_oci 和 pdo_sqlsrv 驱动程序存在已知问题。如果您需要使用其中一个,请参阅 Doctrine 的驱动程序页面获取更多信息。