Mysql utf-8 behaves differently into different environments

character-setMySQL

I have MySQL server under docker in 2 different environments:

This is my create database:

CREATE DATABASE guests CHARACTER SET utf8mb4 COLLATE UTF8MB4_UNICODE_CI;

This is the create table:

USE guests;
CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL);

This is how I Insert data:

insert into MyGuests (firstName)  VALUES("בדיקה");
insert into MyGuests (firstName)  VALUES("ة التي تح");
insert into MyGuests (firstName)  VALUES("???7??");

In the one environment, I get question marks in the result.
In the other environment, I get the correct characters

enter image description here

The good environment is mysql in a docker under windows 10.
The bad one is mysql in a docker under Ubuntu.

This is the result for running:

This is the output of the command mysql> show variables like '%collation%'; in the bad env.

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+

This is the output of the command mysql> show variables like '%collation%'; in the good env.

+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database   | utf8mb4_bin        |
| collation_server     | latin1_swedish_ci  |
+----------------------+-------------------=+

Thanks

Best Answer

I had missing in the connection string CharSet=utf8mb4 in the bad env

Server=10.5.0.5;Database=db;Port=3306;Uid=root;Pwd=root;CharSet=utf8mb4