tags:

views:

1049

answers:

5

How to store symbol for Euro currency in MySQL Database ?

A: 

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

knoopx
+3  A: 

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

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

Also, add this to your connection string in the client to make sure the connection uses 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
Gonzalo
+5  A: 

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;

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
Andomar
A: 

As long as your database is running a version new enough to support unicode (I think it's MySQL 4.1) then all you need to do is specify the UTF-8 encoding on the relevant column(s).

Matt Ball
+1  A: 

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.

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.

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

JasonTrue