MySQL 如何在mysql数据库中存储欧元符号?

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

How to store Euro Symbol in mysql database?

mysqlsymbols

提问by Rachel

How to store symbol for Euro currency in MySQL Database ?

如何在 MySQL 数据库中存储欧元货币符号?

回答by Andomar

Create a column with a character set that supports the Euro character.

使用支持欧元字符的字符集创建一个列。

CREATE TABLE MyTable
(
    MyEuroColumn VARCHAR(5)
      CHARACTER SET utf8
      COLLATE utf8_general_ci 
);

If your editor doesn't support Unicde, you can insert it like;

如果你的编辑器不支持 Unicde,你可以像这样插入它;

select concat('Five ', _ucs2 0x20AC, ' please!')

You can also store the Euro symbol in other character sets:

您还可以将欧元符号存储在其他字符集中

UTF-8                  0xE282AC
UCS-16                 0x20AC
ISO-8859-15 (latin-9)  0xA4

回答by Gonzalo

If the table or the column is set to use utf8 encoding, something like this works fine:

如果表或列设置为使用 utf8 编码,则类似这样的工作正常:

insert into test values (1, ' <- euro');

Also, add this to your connection string in the client to make sure the connection uses UTF8:

此外,将此添加到客户端中的连接字符串以确保连接使用 UTF8:

CharSet=UTF8;

The table I used for testing follow:

我用于测试的表如下:

CREATE TABLE  `g`.`test` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(10) character set utf8 NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

回答by JasonTrue

While I also recommend UTF-8, I wanted to add some clarification of why you may be having trouble storing the Euro symbol in other encodings.

虽然我也推荐 UTF-8,但我想补充说明为什么您可能无法将欧元符号存储在其他编码中。

The Euro symbol was added as a patch to existing Windows and Mac legacy encodings circa 1997. In Windows-1252, the Windows latin-1 character set, the codepoint chosen was 0x80, and MacRoman chose a different location. That's all fine, but many applications specify iso-8859-1 encoding in their MySql database Schema for Latin 1-General text, or mark their HTML output in web applications with iso-8859-1. Iso-8859-1 was never, to my knowledge, officially updated to map a codepoint for the Euro symbol. The latin1 encoding that does support the Euro is the infrequently used iso-8859-15.

欧元符号作为补丁添加到大约 1997 年的现有 Windows 和 Mac 旧编码。在 Windows-1252 中,Windows latin-1 字符集,选择的代码点是 0x80,MacRoman 选择了不同的位置。这一切都很好,但是许多应用程序在它们的 MySql 数据库模式中为拉丁文 1-General 文本指定 iso-8859-1 编码,或者使用 iso-8859-1 在 web 应用程序中标记它们的 HTML 输出。据我所知,Iso-8859-1 从未正式更新以映射欧元符号的代码点。支持欧元的 latin1 编码是很少使用的 iso-8859-15。

So, if you are using iso-8859-1 encodings in your schema, you will have undefined, or worse, behavior.

因此,如果您在架构中使用 iso-8859-1 编码,则会出现未定义的或更糟的行为。

回答by knoopx

I don't know what your really want but there is no problem in storing it into a VARCHAR with utf-8 encoding

我不知道你真正想要什么,但是用 utf-8 编码将它存储到 VARCHAR 中没有问题