简体   繁体   中英

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.

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"

In MySQL Workbench (8.0), you can click the Administration tab, select Options File under Instance , scroll to the International section and you'll find character-set-server and collation-server , which you can set to your desired charset and collation. Click the Apply button to save the changes.

This will set the values in /etc/mysql/my.cnf, or wherever your config file is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM