char在mysql中的意思,导入数据时,quotechar在mysql中是什么意思?

Someone sent me a xlsx excel file and I opened it with excel and saved as csv with utf8 encoding.

I use mysql workbench import wizard to import an excel-made utf8 csv file to a database table. But the imported result missed some data (less than it should have).

And I think it has something to do with the quotechar.

By default the quotechar is double quote but I have some data like this (mixing single quote and double quote):

8'10" foo bar

4" x 6" foo foo bar

I've try to omit the value but it can't (see the error from the pic).

So here I want to figure out:

What does quotechar mean here? How does it work? Why does it matter? Can't it just import everything from the csv file?

How can I import the data correctly while my data mixes single quote and double quote (later I need to retrieve them and use as search keywords, so it'd be better to keep the original form)?

8Cd3j.png

my data looks like this in excel:

2f7nY.png

解决方案

You are going to export your data from Excel as a CSV, I assume, so how this looks in Excel is irrelevant.

When you export the data from excel as a CSV format it's going to encapsulate your data in double quotes. Any double quotes in the data itself is going to be escaped by a second double quote automatically by excel.

As an example, if your data is:

8"

When you export it will be:

"8"""

You have to tell Mysql that you are enclosing strings in character ". That is the quotechar it's talking about. It's the second field on that form you are filling out.

I'm not sure how picky MySQl is going to be here since I haven't imported CSV to Mysql in forever and ever and ever. The trick with the Excel CSV output is that if you have data like:

8"

8'

It will output it as CSV:

"8"""

8'

The second record/field doesn't gain the double quote encapsulation since it doesn't contain a character that requires encapsulation (A double quote, a carriage return, or a line feed).

Mysql might choke on that second record (Hopefully it's import process is robust enough to handle encapsulated and non-encaps'd fields though)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值