Get the App
SLTechnology News&Howtos  ›  Database  › 

How to change the default character set of mysql to utf8 under MAC

Shulou Source: shulou.com Published: 2022-05-31 20:59:49 11月20日 Update

Xiaobian to share with you how to modify the default character set of mysql under MAC to utf8, I hope you have gained something after reading this article, let's discuss it together!

1. Check the character set of mysql installed by default

mysql> show variables like '%char%';

+--------------------------+--------------------------------------------------------+

| 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 | latin1 |

| character_set_system | utf8 |

| character_sets_dir | /usr/local/mysql-5.5.23-osx10.6-x86_64/share/charsets/ |

+--------------------------+--------------------------------------------------------+

8 rows in set (0.00 sec)

Character_set_database and character_set_server are still latin1 character sets, which means that all subsequent tables created by mysql are latin1 character sets, not utf8, which causes some trouble. So it is necessary to modify my.cnf, before modifying my.cnf must close the mysql process, otherwise you will encounter mysql sock can not connect the problem.

2. Close the mysqld daemon

System preferences control mysqld, avoiding the trouble of finding the mysqld installation location.

Click Stop MySQL Server

3. Modify mysql configuration file/etc/my.cnf

sudo cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

sudo vi /etc/my.cnf

The [client] section adds:

default-character-set=utf8

[mysqld] Part added:

character-set-server=utf8

Start mysql after the modification is complete

4. Inspection results:

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/local/mysql-5.5.23-osx10.6-x86_64/share/charsets/ |

+--------------------------+--------------------------------------------------------+

8 rows in set (0.00 sec)

Change completed #

After reading this article, I believe you have a certain understanding of "how to modify mysql default character set to utf8 under MAC". If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Tags: Characters character sets articles processes parts trouble check necessary that is location preferences background done files more knowledge systems results industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Xiaomi MySQL Shulou Technology