Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set MySQL environment/session variables to UTF-8 #796

Open
carrythebanner opened this issue Aug 13, 2024 · 0 comments
Open

Set MySQL environment/session variables to UTF-8 #796

carrythebanner opened this issue Aug 13, 2024 · 0 comments

Comments

@carrythebanner
Copy link
Collaborator

carrythebanner commented Aug 13, 2024

Following #332, the database itself is now UTF-8. However, MySQL session's terminal output still shows ? in place of non-ASCII characters. This is because MySQL itself has some character set and collation settings which are analogous to the database/table ones. Show the values by running this statement:

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

and you'll get output like this:

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | latin1             |
| character_set_connection | latin1             |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | latin1             |
| character_set_server     | latin1             |
| character_set_system     | utf8               |
| collation_connection     | latin1_swedish_ci  |
| collation_database       | utf8mb4_general_ci |
| collation_server         | latin1_swedish_ci  |
+--------------------------+--------------------+
10 rows in set (0.01 sec)

These statements will set those variables to UTF-8:

SET NAMES utf8mb4;
set session character_set_server=utf8mb4;
set session collation_server=utf8mb4_general_ci;

Re-running the above SHOW VARIABLES command now shows:

+--------------------------+--------------------+
| 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_general_ci |
| collation_database       | utf8mb4_general_ci |
| collation_server         | utf8mb4_general_ci |
+--------------------------+--------------------+
10 rows in set (0.01 sec)

That works, and UTF-8 characters now show correctly in the terminal.

However, these settings don't persist across sessions. There are ways to set these for each session, or even better permanently as a config for all sessions, but I wasn't yet able to sniff out exactly how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant