You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to change the system character set and collation for a MySQL server

Practice



Task: on a MySQL 5.5 server (this probably works on lower versions too) change the system CHARACTER SET and COLLATION settings.

1) Edit the my.cnf file. Add (or change the existing) entries to look like this:

character-set-server = utf8
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'

(accordingly, replace utf8 with the encoding you need).


2) Restart the MySQL server.


3) Verify. Log in to the server console and run:

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

and also:
mysql> show variables like 'collat%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
Relevant for: MySQL 5.5

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)