douqin6785 2012-10-16 01:34
浏览 26

如何从数据库中获取原始插入语句[重复]

Possible Duplicate:
Get Insert Statement for existing row in MySQL

Lets say we have a table called users:

CREATE TABLE IF NOT EXISTS users(
UID int(11) PRIMARY KEY NOT NULL auto_increment,
fname varchar(100) default NULL,
lname varchar(100) default NULL,
username varchar(20) default NULL UNIQUE,
password blob   
)ENGINE=InnoDB DEFAULT CHARSET=utf8

Lets assume there's a few rows filled up in the table. I know there is a query that returns the creation of the table -> SHOW CREATE TABLE users But I'm looking to recreate individual insert statements to save them in a log...I know this sounds weird, but I am making a custom CMS where everything is logged, and hopefully where updated/deleted rows could rollback at point in time...therefore I would need to recreate exact insertion query from table data (I have searched all over the web for an answer and can't find it...)

Is there a query that would return "automatically" the query that inserted that specific row by primary key?

I am looking for a query that would do this:

SHOW INSERT FROM users WHERE PRIMARY_KEY=2

Returns:

INSERT INTO users (UID,fname,lname,username,password) VALUES (2,'somename','somelastname','someusername','someAESencryptedPassword')

The reason I'm thinking such a query would exist/be possible is because when you backup a database with php myadmin (cpanel) and you open the file, you can actually view each insert to recreate the table with all rows a that point in time...

  • 写回答

2条回答 默认 最新

  • doupa1883 2012-10-16 01:48
    关注

    There is no such command to retrieve the original insert statement. However, you can always remake the insert statement based on the existent table structure and data.

    The following link may help you, where this has already been asked:

    Get Insert Statement for existing row in MySQL

    Another possible option is using mysqldump with php to export the data as SQL statements.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值