获取MySQL中现有行的插入语句 [英] Get Insert Statement for existing row in MySQL

查看:446
本文介绍了获取MySQL中现有行的插入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MySQL,我可以运行查询:

Using MySQL I can run the query:

SHOW CREATE TABLE MyTable;

它将返回特定表的create table语句.如果您已经创建了一个表,并且想在另一个数据库上创建相同的表,这将很有用.

And it will return the create table statement for the specificed table. This is useful if you have a table already created, and want to create the same table on another database.

是否可以为一个已经存在的行或一组行获取insert语句?有些表有很多列,因此能够获得一条插入语句以将行转移到另一个数据库而不必写出插入语句,或者无需将数据导出到CSV然后再导入相同的数据,这对我来说是一件好事进入另一个数据库.

Is it possible to get the insert statement for an already existing row, or set of rows? Some tables have many columns, and it would be nice for me to be able to get an insert statement to transfer rows over to another database without having to write out the insert statement, or without exporting the data to CSV and then importing the same data into the other database.

请澄清一下,我想要的是可以按以下方式工作的东西:

Just to clarify, what I want is something that would work as follows:

SHOW INSERT Select * FROM MyTable WHERE ID = 10;

并为我返回了以下内容:

And have the following returned for me:

INSERT INTO MyTable(ID,Col1,Col2,Col3) VALUES (10,'hello world','some value','2010-10-20');

推荐答案

似乎没有从MySQL控制台获取INSERT语句的方法,但是您可以使用 mysqldump 获取它们.强>像罗伯建议的那样.指定-t可以省略表的创建.

There doesn't seem to be a way to get the INSERT statements from the MySQL console, but you can get them using mysqldump like Rob suggested. Specify -t to omit table creation.

mysqldump -t -u MyUserName -pMyPassword MyDatabase MyTable --where="ID = 10"

这篇关于获取MySQL中现有行的插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆