如何对表的选定列进行mysql转储 [英] How to take mysql dump of selected columns of a table

查看:75
本文介绍了如何对表的选定列进行mysql转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我必须只对表的一列进行mysql dump.由于该表有太多列,因此我不想转储整个表.我必须将此表从一台服务器转储到另一台服务器.知道我该怎么做吗?

I have a requirement in which I have to take mysql dump of just one column of a table. Since that table has too many columns, I don't want to take dump of the full table. I have to get this dump of the table from one server to another. Any idea how I can do this?

推荐答案

如果您想使用包含模式的mysql dump,可以按照以下步骤进行操作:

If you would like to take mysql dump including the schema, it can be done by following the below steps:

创建一个临时表:

create table temp_table like name_of_the_original_table;

将数据复制到temp_table:

duplicating data into temp_table:

insert into temp_table select * from name_of_the_original_table;

删除不必要的字段:

alter table temp_table drop column somecolumn;

发布此信息,您可以通过运行以下命令来获取mysqldump:

post this, you could take a mysqldump by running:

mysqldump -u <username> -p <password> databasename temp_table

如果要进行数据转储(不使用模式),则可以运行以下命令:

If the intention is to take a data dump(without the schema), you can run the below command:

select * from sometable into outfile '/tmp/datadump' fields terminated by '\t' lines terminated by '\n';

这篇关于如何对表的选定列进行mysql转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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