16



I use create database dbname; to create database.
but I want it to created with Character set UTF-8

Anyone know what is the command to use?

shgnInc
  • 1,634
  • 3
  • 21
  • 29
  • note that the database charset is only part of the picture: you have to also set the server and client connection charsets – Javier Dec 27 '09 at 02:49

2 Answers2

26

Use the

CHARACTER SET

option when creating your database, like so:

CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_bin;

also, read the docs...

LukeR
  • 3,086
  • 2
  • 29
  • 25
17

If database name contains nonalphanumeric chars use "`" to quote:

CREATE DATABASE `my-db` CHARACTER SET utf8 COLLATE utf8_general_ci;

When using in shell script quote the quotes with "\"

mysql -p -e "CREATE DATABASE \`my-db\` CHARACTER SET utf8 COLLATE utf8_general_ci;"
luchaninov
  • 343
  • 1
  • 4
  • 10