Name
CREATE DATABASE
Synopsis
CREATE DATABASE [IF NOT EXISTS]database
[options
]
This statement creates a new
database with the name given. You can use the IF NOT
EXISTS
flag to suppress an error message when the statement
fails if a database with the same name already exists. As of Version
4.1.1, a db.opt file is added to the filesystem
subdirectory created for the database in the MySQL
server’s data directory. This file contains a couple
of settings for the database. You can specify these settings as
options to this SQL statement in a comma-separated list.
Currently, two options are
available: CHARACTER SET
and
COLLATE
. Here is an example of how you can create
a database with both of these options:
CREATE DATABASE db1 CHARACTER SET latin1 COLLATE latin1_bin;
Unlike most lists of options, there is no comma between the first option and the second option. Below is the contents of the db.opt file created for this statement:
default-character-set=latin1 default-collation=latin1_bin
For a list of character sets,
use the SHOW CHARACTER SET
statement. For a list
of collation possibilities, use the SHOW COLLATION
statement.
Get MySQL in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.