behaviour of latin1 in mysql
I have some confusion on latin1 behaviour
As per my understanding latin1 supports 256 characters and use 1 byte per character.
I created 2 tables with latin1 and utf8 charset
I am using mysql 5.7
set names latin1;
CREATE TABLE `foo` (
`i` int(11) DEFAULT NULL,
`v` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into foo values ('Ũ');
insert into foo(v) values ('ϧ');
insert into foo(v) values ('þ');
mysql> select v, hex(v) from foo;
+------+--------+
| v | hex(v) |
+------+--------+
| Ũ | C5A8 |
| ϧ | CFA7 |
| þ | C3BE |
+------+--------+
--------------------------------------------
CREATE TABLE foo_utf8 ( `i` int(11) DEFAULT NULL, `v` varchar(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into foo_utf8(v) values ('þ');
insert into foo_utf8(v) values ('ϧ');
insert into foo_utf8(v) values ('Ũ');
mysql> select v, hex(v) from foo_utf8;
+------+----------+
| v | hex(v) |
+------+----------+
| þ | C383C2BE |
| ϧ | C38FC2A7 |
| Ũ | C385C2A8 |
+------+----------+
-----------------------------------
In both the cases client encoding was latin1
I am not able to understand
1. How come I am able to insert characters with unicode greater then 256 in latin table
2. how come I am able to fetch such data from latin1
3. If I am able to insert/ access all characters in Latin1, then why I need ant other encoding like utf8
4. why hex values are different for both the tables with different charset, although client encoding is same
5. why I am able to fetch correct data even though hex values are different and client encoding is same
please help me in understand or share any blogs so that I can go deeper to understand how charset and encoding works
thanks
Madhur
Subject
Views
Written By
Posted
behaviour of latin1 in mysql
837
April 19, 2021 01:48AM
436
April 19, 2021 08:11AM
529
April 19, 2021 12:26PM
456
April 19, 2021 07:15PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.