Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating mysql table with explicit default character set, what if I don't?

In mysql 5.x Whats the difference if I do something like this:

CREATE TABLE aTable (     id                       BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,     aNumber          bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; 

with this:

CREATE TABLE aTable (    id                       BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,    aNumber            bigint(20) DEFAULT NULL ) ENGINE=InnoDB CHARACTER SET=utf8; 

Notice I am not specifying the character set as default in the first one. I couldn't find anything in the mysql docs.

like image 201
DanInDC Avatar asked Jan 25 '10 22:01

DanInDC


People also ask

What is the default MySQL character set?

The default MySQL server character set and collation are latin1 and latin1_swedish_ci , but you can specify character sets at the server, database, table, column, and string literal levels.

Which characters are not allowed in MySQL?

ASCII NUL (U+0000) and supplementary characters (U+10000 and higher) are not permitted in quoted or unquoted identifiers. Identifiers may begin with a digit but unless quoted may not consist solely of digits. Database, table, and column names cannot end with space characters.

What is the use of character set in MySQL?

MySQL includes character set support that enables you to store data using a variety of character sets and perform comparisons according to a variety of collations.

What is default character set?

The default character set in MySQL is latin1 . If you want to store characters from multiple languages in a single column, you can use Unicode character sets, which is utf8 or ucs2 . The values in the Maxlen column specify the number of bytes that a character in a character set holds.


1 Answers

The word DEFAULT is optional there - so the two are equivalent, i.e. they set the default character set for the table.

See the MySQL documentation for CREATE TABLE. Here's the relevant bit:

table_option:     ENGINE [=] engine_name   ... other options ...   | [DEFAULT] CHARACTER SET [=] charset_name   ... more options ... 

You can confirm this using the SHOW CREATE TABLE command.

like image 77
martin clayton Avatar answered Sep 21 '22 08:09

martin clayton