Get Insert Statement for existing row in MySQL(获取 MySQL 中现有行的插入语句)
问题描述
使用 MySQL 我可以运行查询:
Using MySQL I can run the query:
SHOW CREATE TABLE MyTable;
它会返回指定表的创建表语句.如果您已经创建了一个表,并且想要在另一个数据库上创建相同的表,这将非常有用.
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.
是否可以为已经存在的行或一组行获取插入语句?有些表有很多列,如果我能够得到一个插入语句来将行传输到另一个数据库而不必写出插入语句,或者不必将数据导出到 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;
并为我返回以下内容:
INSERT INTO MyTable(ID,Col1,Col2,Col3) VALUES (10,'hello world','some value','2010-10-20');
推荐答案
似乎没有办法从 MySQL 控制台获取 INSERT
语句,但您可以使用 mysqldump 就像 Rob 建议的那样.指定 -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 中现有行的插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取 MySQL 中现有行的插入语句


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01