Skip to main content

Support UTF-8 encoding by specifying the collation and character set when creating a new database or table in MySQL.

-- create DATABASE with UTF-8 collation and UTF-8 charset
CREATE DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci;

-- create TABLE with UTF-8 collation and UTF-8 charset
CREATE TABLE IF NOT EXISTS  `sessions` (
  session_id varchar(40) DEFAULT '0' NOT NULL,
  ip_address varchar(45) DEFAULT '0' NOT NULL,
  user_agent varchar(120) NOT NULL,
  last_activity int(10) unsigned DEFAULT 0 NOT NULL,
  user_data text NOT NULL,
  PRIMARY KEY (session_id),
  KEY `last_activity_idx` (`last_activity`)
)
CHARACTER SET utf8 COLLATE utf8_general_ci;