简体   繁体   English

需要有关将数据从Mysql导入到HDFS的帮助

[英]Need help about importing the data from Mysql to HDFS

I'm trying to import the data from MySQL DB to HDFS using SQOOP. 我正在尝试使用SQOOP将数据从MySQL DB导入到HDFS。 The SQOOP import statement executed fine but when I looked at the HDFS file, some of the fields are showing as \\ character at end of the field (because the MYSQL table field is having a character , between two words but same field). SQOOP导入语句执行得很好,但是当我查看HDFS文件时,某些字段在该字段的末尾显示为\\字符(因为MYSQL表字段在两个单词之间但在同一字段之间有一个character)。 Can you help me how to import this field to HDFS as same as Mysql table field?. 您能帮我如何将该字段与Mysql table字段一样导入到HDFS吗?

Example: MySQL table field (name) is having value as (sami, ramesh) and when I imported it to HDFS using SQOOP, I see this field as sami/ ramesh (different fields like 2 fields). 示例:MySQL表字段(名称)的值为(sami,ramesh),当我使用SQOOP将其导入HDFS时,我将此字段视为sami / ramesh(不同的字段,例如2个字段)。 I wanted to have it as sami, ramesh (as a single field like mySQL field) in HDFS. 我想在HDFS中将其作为sami,ramesh(像mySQL字段那样的单个字段)使用。

Is there any way to do that?. 有什么办法吗? Thanks a lot in advance for your help. 在此先感谢您的帮助。

Without seeing the import statement that you tried, I am not 100% sure about why is that happening... But perhaps the reason is that you are using the default delimiter for fields, which is precisely a comma, so if you want to keep it, you should use a different delimiter, like for example: 没有看到您尝试过的import语句,我不是100%知道为什么会这样...但是也许原因是您对字段使用了默认的定界符,而这正是逗号,所以如果您想保留您应该使用其他分隔符,例如:

--fields-terminated-by \t

Another option would be to use --enclosed-by '\\"' , and it would look like "sami, ramesh". 另一种选择是使用--enclosed-by '\\"' ,它看起来像“ sami,ramesh”。

Hope that helps! 希望有帮助! If it doesn't, please post your import statement to see where the problem is. 如果没有,请发布您的导入语句以查看问题所在。

Typical sqoop cannot resolve your issue. 典型的sqoop无法解决您的问题。 You need to use query (instead of table) and replace ',' while importing the data. 导入数据时,您需要使用查询(而不是表)并替换为','。

--query <statement>

eg 例如

--query select replace(name, ',', ' '), .... from ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM