MySQL 从csv导入mysql时保留特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21242413/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:52:23  来源:igfitidea点击:

Keep special characters when importing into mysql from csv

mysqlcsvimport

提问by MagentoMan

I have a csv file which contains special characters. However, when I import them into my table they do not import. I have the row that needs to contain special characters setup as utf8_general_ci

我有一个包含特殊字符的 csv 文件。但是,当我将它们导入我的表时,它们不会导入。我有需要包含特殊字符的行设置为 utf8_general_ci

However, I am losing the special characters upon phpmyadmin import. For example, the degree symbol is not importing. I viewed my csv file in a text editor and it does contain the special characters.

但是,我在 phpmyadmin 导入时丢失了特殊字符。例如,未导入度数符号。我在文本编辑器中查看了我的 csv 文件,它确实包含特殊字符。

Please help.

请帮忙。

Ok, I figured how to do this. See my answer below.

好的,我想出了如何做到这一点。看我下面的回答。

回答by Raugaral

Only needs change the charset in mysql when try to upload the file. In my case works the charset windows-1252

尝试上传文件时只需要更改mysql中的字符集。在我的情况下,字符集 windows-1252

Charset on mysql

mysql 上的字符集

回答by MagentoMan

Ok,

好的,

for anyone who has this same issue trying to keep the exported csv file in utf8 while keeping the special characters do the following.

对于尝试将导出的 csv 文件保留在 utf8 中同时保留特殊字符的相同问题的任何人,请执行以下操作。

Open up your file in OpenOffice Calc. When you get ready to save it save it as text csv file. While exporting it will ask you what format to save it as. Save it as UTF8 and presto. It does not convert your special characters like excel does.

在 OpenOffice Calc 中打开您的文件。当您准备好保存时,将其另存为文本 csv 文件。导出时,它会询问您将其另存为什么格式。将其另存为 UTF8 并快速保存。它不会像 excel 那样转换您的特殊字符。

Hope that helps someone else.

希望能帮助别人。

回答by Glenn Lawrence

Excel usually outputs CSV as UTF-16, but there are ways to get it to output in UTF-8 as explained here

Excel中通常输出CSV为UTF-16,但有办法得到它的输出UTF-8作为解释这里

If you are on Windows you can also use the standard Notepad text editor to convert the file by selecting UTF-8 encoding in the Save Asdialog as shown below: enter image description here

如果您使用的是 Windows,您还可以使用标准记事本文本编辑器通过在另存为对话框中选择 UTF-8 编码来转换文件,如下所示: enter image description here

回答by Georgio

Try to convert the charset of your csv file to utf8. For exemple with Notepad++

尝试将 csv 文件的字符集转换为 utf8。以 Notepad++ 为例

Encoding -> Convert to UTF-8 without BOM

回答by starko

Maybe you must check setup as csv file. I think you problem begin in this file. Check this and make sure that both coding were the same(csv and sql table)

也许您必须将设置检查为 csv 文件。我认为您的问题始于此文件。检查这个并确保两个编码相同(csv和sql表)