D
D
David It2022-03-29 06:24:39
MySQL
David It, 2022-03-29 06:24:39

How to change encoding when populating data in mysql?

I'm trying to fill in a table in Maria, I'm getting an error with the encoding. How to solve it and where to change? I used mysql and postgresql before - there were no such problems.

MariaDB [(none)]> CREATE DATABASE students;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> CREATE TABLE department( department_id INT PRIMARY KEY AUTO_INCREMENT,  name_department VARCHAR(30));
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> USE students;
Database changed
MariaDB [students]> CREATE TABLE department( department_id INT PRIMARY KEY AUTO_INCREMENT,  name_department VARCHAR(30));
Query OK, 0 rows affected (0.098 sec)

MariaDB [students]> INSERT INTO department (department_id,name_department)  VALUES (1,'Инженерная школа'), (2,'Школа естественных наук');
ERROR 1366 (22007): Incorrect string value: '\xD0\x98\xD0\xBD\xD0\xB6...' for column `students`.`department`.`name_department` at row 1
MariaDB [students]> SET NAMES 'utf8mb4';
Query OK, 0 rows affected (0.001 sec)

MariaDB [students]> SHOW VARIABLES WHERE variable_name LIKE '%char%' OR variable_name LIKE '%coll%';
+--------------------------+------------------------------+
| Variable_name            | Value                        |
+--------------------------+------------------------------+
| character_set_client     | utf8mb4                      |
| character_set_connection | utf8mb4                      |
| character_set_database   | latin1                       |
| character_set_filesystem | binary                       |
| character_set_results    | utf8mb4                      |
| character_set_server     | latin1                       |
| character_set_system     | utf8                         |
| character_sets_dir       | /usr/share/mariadb/charsets/ |
| collation_connection     | utf8mb4_general_ci           |
| collation_database       | latin1_swedish_ci            |
| collation_server         | latin1_swedish_ci            |
+--------------------------+------------------------------+
11 rows in set (0.007 sec)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2022-03-29
@David138

Here . Read in full with comments. You should end up with this:

MariaDB [(none)]> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+------------------------+
| Variable_name            | Value                  |
+--------------------------+------------------------+
| character_set_client     | utf8mb4                |
| character_set_connection | utf8mb4                |
| character_set_database   | utf8mb4                |
| character_set_filesystem | binary                 |
| character_set_results    | utf8mb4                |
| character_set_server     | utf8mb4                |
| character_set_system     | utf8                   |
| collation_connection     | utf8mb4_unicode_520_ci |
| collation_database       | utf8mb4_unicode_520_ci |
| collation_server         | utf8mb4_unicode_520_ci |
+--------------------------+------------------------+
10 rows in set (0.021 sec)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question