Setting character sets on tables and fields
suggest changeYou can set a character set both per table, as well as per individual field using the CHARACTER SET and CHARSET statements:
CREATE TABLE Address (
`AddressID` INTEGER NOT NULL PRIMARY KEY,
`Street` VARCHAR(80) CHARACTER SET ASCII,
`City` VARCHAR(80),
`Country` VARCHAR(80) DEFAULT "United States",
`Active` BOOLEAN DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
A trailing comma after the last column is a syntax error. City and Country use the table default, utf8mb4. The bare name UTF8 means utf8mb3 and cannot store every Unicode character. Street uses ASCII because that column says so.
Setting the right character set is highly dependent on your dataset, but can also highly improve portability between systems working with your data.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents