In the previous post, I have discussed and provided small note on Database Character Set and Collation.
In this post, I show you that how you can configure or change default Character Set in MySQL.
Sometimes it is required to change the default character set of MySQL Server or MySQL Database.
A Character set “latin1” and Collation “latin1_swedish_ci” are the default of MySQL Server.
This is standard configuration and you do not need to change anything but if your application requires to store data using a different character set, you have to change this default configuration.
Here, I am showing to change your default character set and collation to UTF-8.
MySQL Server provides, different three ways to configure character set and collation.
- Configure Character set and Collation at Database Level.
- Configure Character set and Collation at Server Startup.
- Configure Character set and Collation during MySQL Server Installation and Configuration.
First, check your default Character Set and Collation of MySQL Server.
SHOW VARIABLES LIKE 'chara%';
SHOW VARIABLES LIKE 'collation%';
If you want to change default to UTF-8, you want to add the following to my.cnf (MySQL Configuration File).
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Specify Character Settings per Database:
CREATE DATABASE MyDatabase
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.