更新:我的目标是获得一组可以执行的 SQL 命令,并重新创建我创建的数据库,包括所有资源,如表、索引、触发器函数、权限授予等 - 与下面的 MySQL 和 POstgres 命令相同做。我正在开发一个开源项目,我希望能够向最终用户提供一个 sql 文件,因此他们所需要做的就是运行它以正确设置他们的数据库。
在 MySQL 上:
mysqldump --no-data somedatabasename dump_schema_mysql.out
Run Code Online (Sandbox Code Playgroud)
在 Postgres 上:
pg_dump -s somedatabasename > dump_schema_postgres.out
Run Code Online (Sandbox Code Playgroud)
我似乎无法在 Linux 上找到 SQL 服务器的等价物,尽管这样一项常见任务肯定很容易完成?
我的 sqlcmd 实用程序运行正常:
ubuntu@ubuntu:~$ sqlcmd -?
Microsoft (R) SQL Server Command Line Tool
Version 17.6.0001.1 Linux
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-g enable column encryption]
[-G use Azure Active Directory for authentication]
[-? show syntax summary]
ubuntu@ubuntu:~$ sqlcmd -?
Run Code Online (Sandbox Code Playgroud)