MySQL 如何获取将在 PHPMyAdmin 中重新创建 sql 表的查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6983344/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:47:33  来源:igfitidea点击:

How to get query that would recreate sql table in PHPMyAdmin

mysqlsqlrecreate

提问by Borut Flis

I have table on MySQL server and would like to get the SQL that would re-create the table.

我在 MySQL 服务器上有表,并希望获得重新创建该表的 SQL。

How do I get the query to recreate the SQL table?

如何获取重新创建 SQL 表的查询?

采纳答案by liamgriffiths

mysqldump can do it - http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

mysqldump 可以做到 - http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

You can use it like this:

你可以这样使用它:

mysqldump [databasename] [tablename] > mysqltablesql.sql

回答by J.J.

MySQL supports SHOW CREATE TABLEto return the SQL that was used to create a table.

MySQL 支持SHOW CREATE TABLE返回用于创建表的 SQL。

From their docs:

从他们的文档:

mysql> SHOW CREATE TABLE t;
CREATE TABLE t (
  id INT(11) default NULL auto_increment,
  s char(60) default NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM

This can be useful if you have just a connection to the DB, versus a CLI on the server. If you have a CLI, use mysqldump like liamgriffiths recommends.

如果您只连接到数据库,而不是服务器上的 CLI,这会很有用。如果您有 CLI,请像 liamgriffiths 推荐的那样使用 mysqldump。

回答by Casey

If you are using phpMyAdmin, select a table then click the 'Export' tab. One of the output types is SQL. Selecting this will generate a SQL script to create the table and insert all of the data that is currently in the table. Make sure under the dump data option to select 'Structure and Data'

如果您使用的是 phpMyAdmin,请选择一个表,然后单击“导出”选项卡。输出类型之一是 SQL。选择此项将生成一个 SQL 脚本来创建表并插入当前在表中的所有数据。确保在转储数据选项下选择“结构和数据”

回答by Ashwin A

mysqldump [OPTIONS] database [tables]>backup-file.sql

mysqldump [OPTIONS] 数据库 [表]>backup-file.sql

If you don't give any tables or use the --databases or --all-databases, the whole database(s) will be dumped.

如果您不提供任何表或使用 --databases 或 --all-databases,则整个数据库将被转储。

You can get a list of the options your version of mysqldump supports by executing mysqldump --help.

您可以通过执行 mysqldump --help 来获取您的 mysqldump 版本支持的选项列表。

Note that if you run mysqldump without --quick or --opt, mysqldump will load the whole result set into memory before dumping the result. This will probably be a problem if you are dumping a big database.

请注意,如果您在没有 --quick 或 --opt 的情况下运行 mysqldump,mysqldump 将在转储结果之前将整个结果集加载到内存中。如果您要转储大型数据库,这可能会成为问题。

回答by sa125

I'd go with @liamgriffiths proposal of mysqldump, but you could also try create table <new-table-name> like <old-table-name>followed by insert into <new-table-name> select * from <old-table-name>

我会选择@liamgriffiths 的提议mysqldump,但你也可以尝试create table <new-table-name> like <old-table-name>跟随insert into <new-table-name> select * from <old-table-name>

回答by abarrington

If you have access to phpMyAdmin, you can get this code through the Export tab on the table that you require.

如果您有权访问 phpMyAdmin,则可以通过所需表上的“导出”选项卡获取此代码。

Select SQL then make sure you export "Structure" ("CREATE table" code) and "Data" ("INSERT" code) with Export type set to "INSERT".

选择 SQL,然后确保导出“结构”(“创建表”代码)和“数据”(“插入”代码),导出类型设置为“插入”。