0

When I was on a development situation few days ago, I happened to use the following command on mysql CUI after the command use my_dev_database for applying charsets to the specific database:
SET NAMES utf8mb4 COLLATE utf8mb4_general_ci;

I intended to use this command to change "character_set_client" and "character_set_results". But this command happened to cause set characters for other databases (perhaps all databases,) on the same server including the database of my working webSite. I was surprised! But after dozen's seconds, character set for the other databases was recovered automatically, and ones for my_dev_database still maintain the modified character set.

I don't understand this weird behavior of mysql. What was happening during the dozen's second for my working website? If some user submit posts during that, the modified character set was saved in the database for my working website on mysql server?

I'm really worried about that. Any advice would be appreciated.

Damegami
  • 37
  • 5

1 Answers1

0

No, it does not change the charset of databases; it changes the interpretation of the data.

More precisely, SET NAMES declares what encoding the client has. Furthermore, as data moves to/from (via INSERT/SELECT) the server, it is converted from the SET NAMES charset to whatever charset the columns are declared to be.

So, it only appeared that other databases were changed, and that it reverted. Smoke and mirrors.

See "best practice" in here to see that utf8mb4 needs to be set in multiple places to have a consistent, smoothly running, MySQL.

utf8mb4 is the right way to go; the collation is a secondary issue.

Rick James
  • 135,179
  • 13
  • 127
  • 222