我有一个mysqldump备份我的mysql数据库,包括我们所有的表,这是大约440兆。我只想从mysqldump中恢复其中一个表的内容。这可能吗?从理论上讲,我可以只删除重建我想要的表的部分,但我甚至不知道如何有效地编辑这种大小的文本文档。
当前回答
SQL块被“表my_table的表结构”和“转储表my_table的数据”阻塞。
您可以如下所示使用Windows命令行获取各个部分的行号。根据需要调整搜索字符串。
查找/n "for table ' " sql.txt
将返回以下内容:
---------- SQL.TXT
[4384]——my_table的表结构
[4500]——转储表my_table的数据
[4514]——表some_other_table的表结构
... 等。
这就得到了你需要的行号……现在,如果我知道如何使用它们……调查。
其他回答
Get a decent text editor like Notepad++ or Vim (if you're already proficient with it). Search for the table name and you should be able to highlight just the CREATE, ALTER, and INSERT commands for that table. It may be easier to navigate with your keyboard rather than a mouse. And I would make sure you're on a machine with plenty or RAM so that it will not have a problem loading the entire file at once. Once you've highlighted and copied the rows you need, it would be a good idea to back up just the copied part into it's own backup file and then import it into MySQL.
前面提到的“sed”解决方案很好,但不是100%安全
你可以使用INSERT命令,其中的数据包含: ... 创建表(无论)……mytable… 或者甚至是精确的字符串"CREATE TABLE ' mytable ';" 如果您正在存储DML命令,例如!
(如果表很大,你不需要手动检查)
我会验证所使用的转储版本的确切语法,并有一个更严格的模式搜索:
避免”。*”并使用“^”来确保我们从行开头开始。 我更喜欢抓住最初的DROP
总而言之,这对我来说更好:
sed -n -e '/^DROP TABLE IF EXISTS \`mytable\`;/,/^UNLOCK TABLES;/p' mysql.dump > mytable.dump
表应该在转储和数据库中呈现相同的结构。
`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql.tar.gz | mysql -u<user> -p<password> database_name`
or
`zgrep -a ^"INSERT INTO \`table_name" DbDump-backup.sql | mysql -u<user> -p<password> database_name`
我使用了uloBasEI的sed命令的修改版本。它包括前面的DROP命令,读取直到mysql完成转储数据到你的表(解锁)。为我工作(重新)导入wp_users到一堆Wordpress网站。
sed -n -e '/DROP TABLE.*`mytable`/,/UNLOCK TABLES/p' mydump.sql > tabledump.sql
我尝试了一些选择,它们都非常慢。这将在几分钟内将一个360GB的转储拆分到它的表中:
如何将mysqldump的输出分割成更小的文件?
推荐文章
- 如何关闭mysql密码验证?
- MySQL区分大小写查询
- MySQL数据库表中的最大记录数
- 原则-如何打印出真正的sql,而不仅仅是准备好的语句?
- PHP/MySQL插入一行然后获取id
- 如何从命令行通过mysql运行一个查询?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- 输入文件似乎是一个文本格式转储。请使用psql
- 如何从命令行在windows中找到mysql数据目录
- 如何找到MySQL的根密码
- 如何改变字符集(和排序)在整个数据库?
- mySQL:: insert到表,数据从另一个表?
- 重复键忽略?
- 将表从一个数据库复制到另一个数据库的最简单方法?
- 如何通过查询在MySQL中获得数据库结构?