Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default character set on MySQL Workbench

I am trying to connect to my MYSQL database using a utf8mb4 charset (Note the global settings for the database charset is already utf8mb4).

I can do this quite easily using the CLI like so:

mysql -h myhostname -u myuser -p --default-character-set=utf8mb4

When I do the following query:

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

I get the correct output as expected:

+--------------------------+--------------------+
| 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_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

However, when I connect to my MySQL database using MySQL Workbench, and perform the same query I get the following:

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8               |
| character_set_connection | utf8               |
| character_set_database   | latin1             |
| character_set_filesystem | binary             |
| character_set_results    | utf8               |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8_general_ci    |
| collation_database       | latin1_swedish_ci  |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

The issue here is that I am struggling to change the default-character-set in MySQL Workbench GUI. I tried appending the following:

default-character-set=utf8mb4

in Manage Server Connections > Connection > Advanced > Others section,

but does not seem to have any affect.

How can I change the default character set on the MySQL Workbench GUI.

like image 437
Yahya Uddin Avatar asked Jun 04 '18 15:06

Yahya Uddin


1 Answers

AFAIK you have to execute this command each time you start a new Workbench session:

SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';

UPDATE

The following is useful if you need to use Workbench to do exports: (I haven't found a similar way to cause all it's connections to default to utf8mb4)

The default charset that is used is to export data is utf8. To support full Unicode though we need utf8mb4. To achieve this it's possible to modify Workbench to use utf8mb4 manually.

  • Go to C:\Program Files\MySQL\MySQL Workbench 6.3 CE\modules open this file wb_admin_export.py.
  • Create a backup copy
  • Replace all occurrences "default-character-set":"utf8" with "default-character-set":"utf8mb4".
  • Save the file.
  • Restart Workbench.

The next time you run the export you will see in the log results like this:

Running: mysqldump.exe --defaults-file="c:\users\jonathan\appdata\local\temp\tmpidlh7a.cnf" --host=localhost --protocol=tcp --user=root --allow-keywords=TRUE --port=3306 --default-character-set=utf8mb4 --routines --skip-triggers "databasename"

like image 139
J. Schmale Avatar answered Sep 24 '22 11:09

J. Schmale