Mysql charset

download Mysql charset

of 31

  • date post

    26-Jun-2015
  • Category

    Technology

  • view

    5.272
  • download

    1

Embed Size (px)

Transcript of Mysql charset

  • 1. MySQL OSC2011.DB MySQL2011-11-05MySQL - OSC2011.DBPowered by Rabbit 1.0.4

2. MySQL (NSEG) mailto:tommy@mysql.gr.jp id:tmtms @tmtms 1/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 3. MySQL 2/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 4. charsetcollationMySQL - OSC2011.DB 3/30 Powered by Rabbit 1.0.4 5. charset show charset utf8mb4 : 4UTF-8 (MySQL5.5) utf8 : 3UTF-8 eucjpms, cp932, ... 4/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 6. collation show collation utf8_general_ci, utf8_bin,utf8_unicode_ci, ... 5/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 7. utf8_general_ci charset utf8 collation ASCII/ A=a 6/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 8. utf8_bin char(n) binary collation A != a7/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 9. utf8_unicode_ci Unicode Collation Algorithm (UCA) collation //// A= ====== http://tmtm.org/tmp/mysql_unicode_collation.html 8/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 10. 9/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 11. mysql> show variables like char%;+--------------------------+----------------------------------+| Variable_name| Value|+--------------------------+----------------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results| utf8 || character_set_server | latin1 || character_set_system | utf8 || character_sets_dir | /usr/local/mysql/share/charsets/ |+--------------------------+----------------------------------+ 10/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 12. utf8 11/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 13. charset charset create database db1 charset utf8; show create database db1;12/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 14. charset charset create table t1 (...) charset utf8; show create table t1; 13/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 15. charset charset create table t1 (s char(10) charset cp932,u char(10) charset utf8 );14/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 16. / charset set names utf8; 15/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 17. mysql> insert into t1 (s,u) values (,); mysql> select * from t1; +------+------+ | s| u| +------+------+ | | | +------+------+ mysql> select hex(s),hex(u) from t1; +--------+--------+ | hex(s) | hex(u) | +--------+--------+ | 82A0 | E38182 | +--------+--------+ 16/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 18. MySQL - OSC2011.DB 17/30 Powered by Rabbit 1.0.4 19. ? mysql> insert into t1 (s,u) values (, ); mysql> select * from t1; +------+------+ | s| u| +------+------+ | ?| | +------+------+ mysql> select hex(s),hex(u) from t1; +--------+--------+ | hex(s) | hex(u) | +--------+--------+ | 3F | E298BA | +--------+--------+ 18/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 20. ? mysql> set names cp932; mysql> select * from t1; +------+------+ | s| u| +------+------+ | ?| ?| +------+------+ mysql> select hex(s),hex(u) from t1; +--------+--------+ | hex(s) | hex(u) | +--------+--------+ | 3F | E298BA | +--------+--------+19/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 21. ? HEX() MySQL - OSC2011.DB 20/30 Powered by Rabbit 1.0.4 22. charset mysql> show variables like char%;+--------------------------+----------------------------------+| Variable_name| Value|+--------------------------+----------------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results| utf8 || character_set_server | latin1 || character_set_system | utf8 || character_sets_dir | /usr/local/mysql/share/charsets/ |+--------------------------+----------------------------------+ 21/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 23. PHPmysql !22/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 24. charset 23/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 25. create table t ( email char(255) unique ) charset utf8mb4; ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes 24/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 26. Illegal mix of collationscreate table t2 ( a char(10) charset ascii, u char(10) charset utf8);select * from t2 where a=;ERROR 1267 (HY000): Illegal mix of collations(ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation =25/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 27. set names ascii; select * from t2 where u=ABC; ASCII UTF-8 !? 26/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4 28. collate collation collation27/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 29. collateselect * from t2 where a=;ERROR 1267 (HY000): Illegal mix of collations(ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation =select * from t2 where a= collate utf8_general_ci; OK28/30MySQL - OSC2011.DBPowered by Rabbit 1.0.4 30. MySQL - OSC2011.DB 29/30 Powered by Rabbit 1.0.4 31. ? HEX() utf8 30/30MySQL - OSC2011.DB Powered by Rabbit 1.0.4