Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion with utf8_general_ci & utf8_unicode_ci

Mysql server collation is utf8_general_ci in my.cnf

I am using utf8_general_ci collation for database, now i have created few tables with utf8_unicode_ci collation in same database.

Now i would like to use utf8_unicode_ci for server/database/tables/fields. In order to do that first i need to change collation for server to utf8_unicode_ci then for database, tables and fields.

My question is i already have data in tables stored using utf8_general_ci, can i just keep as it is without doing anything to data Or do i need to do any kind of conversion.

Other thing is, as you can see server level collation is utf8_general_ci but at table and field level is utf8_unicode_ci, so with my current setup when i store and retrieve data from these tables what collation mysql use?

Thank you.

like image 620
Raj Janorkar Avatar asked Jan 27 '26 17:01

Raj Janorkar


1 Answers

"Server level" collation means nothing.
Server and database level charset (and collation) serve as mere default values for the table (and database) creation.

  • Say, if you didn't supply any collation when created a database, it will be created using server collation. But if you do - the supplied one will be used and server collation won't interfere at all.
  • If you didn't supply any collation in table definition, the table will be created using database collation. But if you do - the supplied one will be used and neither server nor database collation will affect your queries.

It's only table and field level collation that matters.

if i already have data in tables stored using utf8_general_ci, can i just keep as it is

Yes. You can have tables with any charset in your database.

like image 181
Your Common Sense Avatar answered Jan 30 '26 08:01

Your Common Sense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!