Mysql change collation or character set

http://blog.arkency.com/2015/05/how-to-store-emoji-in-a-rails-app-with-a-mysql-database/

http://dev.mysql.com/doc/refman/5.7/en/charset-syntax.html

Database level

CREATE DATABASE czech_slovak_names CHARACTER SET = 'keybcs2' COLLATE = 'keybcs2_bin';
ALTER DATABASE czech_slovak_names COLLATE = 'keybcs2_general_ci';

Table level

CREATE TABLE english_names (id INT, name VARCHAR(40))
CHARACTER SET 'utf8'
COLLATE 'utf8_icelandic_ci';

ALTER TABLE table_name
CONVERT TO CHARACTER
SET charset_name [COLLATE collation_name];

ALTER TABLE table_name MODIFY ascii_text_column TEXT CHARACTER SET utf8;
ALTER TABLE table_name MODIFY ascii_varchar_column VARCHAR(M) CHARACTER SET utf8;

Column level

CREATE TABLE european_names (
 croatian_names VARCHAR(40) COLLATE 'cp1250_croatian_ci',
 greek_names VARCHAR(40) CHARACTER SET 'greek');

To store emoji, or non utf8 character

 ALTER TABLE personals
 MODIFY self_introduction
 TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s