如何使用 SQL 查询转储没有数据的 mysql 表结构?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4294507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to dump mysql table structure without data with a SQL query?
提问by Hurans
I need to export a mysql table, but it has like 5gb of entries, so I only want the structure. I am trying to do it from a simple php doing a sql query, how can I do that?
我需要导出一个 mysql 表,但它有 5GB 的条目,所以我只想要结构。我试图从一个简单的 php 做一个 sql 查询,我该怎么做?
回答by RedFilter
You can use SHOW CREATE TABLE
for this.
您可以SHOW CREATE TABLE
为此使用。
Shows the CREATE TABLE statement that creates the given table. The statement requires the SELECT privilege for the table. As of MySQL 5.0.1, this statement also works with views.
显示创建给定表的 CREATE TABLE 语句。该语句需要对该表具有 SELECT 权限。从 MySQL 5.0.1 开始,此语句也适用于视图。
E.g.:
例如:
SHOW CREATE TABLE MyTablename
回答by mp31415
回答by gan gary
if u have "MySQL Workbench" v6.0
如果你有“MySQL Workbench”v6.0
1) click on any table of the database.
1) 单击数据库的任意表。
2) Right-click and select "Tables Maintenance"
2) 右键单击并选择“表维护”
3) Under "Tables" tab, highlight the tables u want to export, right-click and select "Send to SQL Editor">"Create Schema"
3) 在“表”选项卡下,突出显示要导出的表,右键单击并选择“发送到 SQL 编辑器”>“创建架构”
回答by Pramatha V
It is already answered in the link below:
MySql export schema without data
它已经在下面的链接中得到了回答:
MySql export schema without data
Use the command below to take the structure or schema dump.
使用以下命令获取结构或模式转储。
mysqldump -u root -p --no-data dbname > schema.sql
回答by Paul Creasey
Depending on you exact requirements, something as simple as
根据您的确切要求,一些简单的事情
select * from table where 1=0
might suffice.
可能就足够了。