MySQL 如何将 mysqldump 用于表的一部分?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5658284/
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
How to use mysqldump for a portion of a table?
提问by datasn.io
So I can export only a table like this:
所以我只能导出这样的表:
mysqldump -u root -p db_name table_name > table_name.sql
Is there any way to export only a portion of a table with mysqldump? For example, 0 - 1,000,000 rows, 1,000,000 - 2,000,000 rows, etc.
有没有办法用mysqldump只导出表的一部分?例如,0 - 1,000,000 行、1,000,000 - 2,000,000 行等。
Should I do this with mysqldumpor a query?
我应该用mysqldump还是查询来做到这一点?
回答by neocanable
mysqldump -uroot -p db_name table_name --where='id<1000000'
or you can use
或者你可以使用
SELECT * INTO OUTFILE 'data_path.sql' from table where id<100000
回答by noisex
mysqldump --skip-triggers --compact --no-create-info --user=USER --password=PASSWORD -B DATABASE --tables MY_TABLE --where='SOME_COLUMN>=xxxx' > out.sql
回答by user2755358
The file dumped is different from the file you use SQL select. For the 2nd approach, you can not simply use: mysql database < table to dump the table into a database.
转储的文件与您使用 SQL select 的文件不同。对于第二种方法,您不能简单地使用:mysql database < table 将表转储到数据库中。
回答by sadanand patel
mysqldump -uroot -p db_name table_name --where'id<1000000' > yourdumpname.sql
回答by sachin_ur
Below query is to select from id range you can use date_createdor any instead of id
下面的查询是从 id 范围中进行选择,您可以使用date_created或 any 代替id
mysqldump --opt --host=dns --user=user_name --password=your_passwd db_name --tables table_name --where "id > 1 and id < 100 " > /file_name.sql
ex: --where="date_created > '2019-01-18' "
--> insted of id
例如:--where="date_created > '2019-01-18' "
--> 插入id
回答by Anton Zarkov
In my case i have execute this:
在我的情况下,我已经执行了这个:
SELECT *
INTO OUTFILE 'C:\Documents and Settings\Anton.Zarkov\Desktop\joomla_export\data_AZ.sql'
FROM `jos_glossary`
WHERE id>6000
- there is no syntax error - the query passes through.
- The result is
NULL
- no rows were written. (I'm sure - the last ID is 6458) - If I repeat the query a
n error occurs => #1086 - File 'C:Documents and SettingsAnton.ZarkovDesktopjoomla_exportdata_AZ.sql' already exists
- Unfortunately I cannot find the "existing" file anywhere on disk C. Where is it?
- The result is
- 没有语法错误 - 查询通过。
- 结果是
NULL
- 没有写入任何行。(我确定 - 最后一个 ID 是 6458) - 如果我重复查询 a
n error occurs => #1086 - File 'C:Documents and SettingsAnton.ZarkovDesktopjoomla_exportdata_AZ.sql' already exists
- 不幸的是,我在磁盘 C 上的任何地方都找不到“现有”文件。它在哪里?
- 结果是
The conditions are: phpMyAdmin SQL Dump; version 3.4.5; host: localhost; server version: 5.5.16; PHP version: 5.3.8
条件是: phpMyAdmin SQL Dump;版本 3.4.5;主机:本地主机;服务器版本:5.5.16;PHP版本:5.3.8