143
GitHub - voidint/tsdump: Database table structure dump tool.
source link: https://github.com/voidint/tsdump?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
tsdump
注意:master
分支可能处于开发之中并非稳定版本,请通过tag下载稳定版本的源代码,或通过release下载已编译的二进制可执行文件。
- 支持将数据库(当前仅支持
MySQL
)及其表结构的元数据以text
、markdown
、json
、csv
、xlsx
形式输出。
-
源代码安装
$ GO111MODULE=on GOPROXY=https://goproxy.cn go install -v github.com/voidint/[email protected]
-
二进制安装
$ tsdump --help
NAME:
tsdump - Database table structure dump tool.
USAGE:
tsdump [OPTIONS] [database [table ...]]
VERSION:
0.5.0
AUTHOR:
voidint <[email protected]>
OPTIONS:
-D, --debug enable debug mode
-h value, --host value connect to host (default: "127.0.0.1")
-P value, --port value port number to use for connection (default: 3306)
-S value, --socket value socket file to use for connection
-u value, --user value user for login if not current user (default: "voidint")
-p value, --password value password to use when connecting to server. If password is not given it's solicited on the tty.
-V value, --viewer value output viewer. Optional values: csv|json|md|xlsx|txt (default: "txt")
-o value, --output value write to a file, instead of STDOUT
-s, --sorted sort table columns
--help show help
--version, -v print the version
COPYRIGHT:
Copyright (c) 2017-2021, voidint. All rights reserved.
-
使用
root
用户创建一个名为mydb
的数据库实例,以及一张student
的表。CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `mydb`; CREATE TABLE `student` ( `sno` char(8) NOT NULL COMMENT '学号', `sname` varchar(255) NOT NULL COMMENT '姓名', `gender` char(2) DEFAULT NULL COMMENT '性别', `native` char(20) DEFAULT NULL COMMENT '籍贯', `birthday` datetime DEFAULT NULL COMMENT '出生日期', `dno` char(6) DEFAULT NULL COMMENT '所在院系', `spno` char(8) DEFAULT NULL COMMENT '专业代码', `classno` char(4) DEFAULT NULL COMMENT '班级号', `entime` date DEFAULT NULL COMMENT '入校时间', `home` varchar(40) DEFAULT NULL COMMENT '家庭住址', `tell` varchar(40) DEFAULT NULL COMMENT '联系电话', PRIMARY KEY (`sno`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生信息表';
-
将目标数据库及其所有表的表结构数据以表格形式输出到console
$ tsdump -h 127.0.0.1 -P 3307 -u root mydb Enter Password: |----------|---------------|--------------------| | DATABASE | CHARACTER SET | COLLATION | |----------|---------------|--------------------| | mydb | utf8mb4 | utf8mb4_general_ci | |----------|---------------|--------------------| TABLE: student 学生信息表 |----------|--------------|----------|-----|---------|---------------|--------------------|----------| | COLUMN | DATA TYPE | NULLABLE | KEY | DEFAULT | CHARACTER SET | COLLATION | COMMENT | |----------|--------------|----------|-----|---------|---------------|--------------------|----------| | sno | char(8) | NO | PRI | | utf8mb4 | utf8mb4_general_ci | 学号 | | sname | varchar(255) | NO | | | utf8mb4 | utf8mb4_general_ci | 姓名 | | gender | char(2) | YES | | | utf8mb4 | utf8mb4_general_ci | 性别 | | native | char(20) | YES | | | utf8mb4 | utf8mb4_general_ci | 籍贯 | | birthday | datetime | YES | | | | | 出生日期 | | dno | char(6) | YES | | | utf8mb4 | utf8mb4_general_ci | 所在院系 | | spno | char(8) | YES | | | utf8mb4 | utf8mb4_general_ci | 专业代码 | | classno | char(4) | YES | | | utf8mb4 | utf8mb4_general_ci | 班级号 | | entime | date | YES | | | | | 入校时间 | | home | varchar(40) | YES | | | utf8mb4 | utf8mb4_general_ci | 家庭住址 | | tell | varchar(40) | YES | | | utf8mb4 | utf8mb4_general_ci | 联系电话 | |----------|--------------|----------|-----|---------|---------------|--------------------|----------|
-
将目标数据库下目标表的表结构数据输出到markdown文件
$ tsdump -h 127.0.0.1 -P 3307 -u root -V md -o ./student.md mydb student
output:
DATABASE CHARACTER SET COLLATION mydb utf8mb4 utf8mb4_general_ci student
学生信息表
COLUMN DATA TYPE NULLABLE KEY DEFAULT CHARACTER SET COLLATION COMMENT sno char(8) NO PRI utf8mb4 utf8mb4_general_ci 学号 sname varchar(255) NO utf8mb4 utf8mb4_general_ci 姓名 gender char(2) YES utf8mb4 utf8mb4_general_ci 性别 native char(20) YES utf8mb4 utf8mb4_general_ci 籍贯 birthday datetime YES 出生日期 dno char(6) YES utf8mb4 utf8mb4_general_ci 所在院系 spno char(8) YES utf8mb4 utf8mb4_general_ci 专业代码 classno char(4) YES utf8mb4 utf8mb4_general_ci 班级号 entime date YES 入校时间 home varchar(40) YES utf8mb4 utf8mb4_general_ci 家庭住址 tell varchar(40) YES utf8mb4 utf8mb4_general_ci 联系电话 -
将用户权限范围内数据库及其表结构数据输出到csv文件
$ tsdump -h 127.0.0.1 -P 3307 -u root -V csv > ./mydb.csv
-
将目标数据库及其所有表的表结构数据输出到JSON文件
$ tsdump -h 127.0.0.1 -P 3307 -u root -V json mydb > mydb.json
Changelog
0.5.0 - 2021/11/16
0.4.2 - 2020/05/22
- 更新依赖(xorm)避免
go get
编译错误
0.4.1 - 2020/01/05
- 修订版权信息
0.4.0 - 2018/03/25
0.3.0 - 2018/01/05
0.2.0 - 2018/01/01
0.1.0 - 2017/12/31
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK