MySQL Create Database with UTF8 Character Set Syntax
June 21st, 2013
Warning: This post is 11 years old. Some of this information may be out of date.
I always forget the MySQL create database with UTF8 character set syntax, so here it is:
CREATE DATABASE `mydb` CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL ON `mydb`.* TO `username`@localhost IDENTIFIED BY 'password';
Alternatively, you can use 'CREATE SCHEMA' instead of 'CREATE DATABASE':
CREATE SCHEMA `mydb` CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL ON `mydb`.* TO `username`@localhost IDENTIFIED BY 'password';
I hope this helps someone else too!
UPDATE: This post used to show the FLUSH PRIVILEGES
command after the GRANT
statements but, as pointed out by Scott Lindsey in the comments, FLUSH PRIVILEGES
is unnecessary. Read the MySQL documentation for information on why this isn't needed.