How to change the default character set of MySQL to utf8 on MAC

How to change the default character set of MySQL to utf8 on MAC

1. Check the character set of the default installed MySQL

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 the tables created by MySQL later are all in latin1 character sets, not utf8, which will cause some trouble. Therefore, it is necessary to modify my.cnf. Be sure to close the MySQL process before modifying my.cnf, otherwise you will encounter the problem that MySQL's sock cannot connect.

2. Close the mysqld background process

Control mysqld in the system preferences, avoiding the trouble of finding the installation location of mysqld.

Click Stop MySQL Server

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

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

sudo vi /etc/my.cnf

[client] section added:

default-character-set=utf8

[mysqld] section added:

character-set-server=utf8

After the modification is completed, start mysql

4. Check the 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)

Modification completed#

You may also be interested in:
  • MySQL character set viewing and modification tutorial
  • How to modify the MySQL character set
  • How to change MySQL character set utf8 to utf8mb4
  • MySQL startup error 1067 and invalid recovery after changing character set and restarting
  • How to change the character set encoding to UTF8 in MySQL 5.5/5.6 under Linux
  • How to modify the default character set encoding in MySQL
  • How to modify the default character set of MySQL to utf-8 through my.cnf and precautions
  • How to modify and view the character set of MySql tables, fields, and libraries
  • How to modify the database encoding (database character set) and the character encoding of the table in MySQL
  • Detailed analysis of two methods to modify the MySQL default character set
  • Sharing of MySQL character set and database engine modification methods
  • Practical tutorial on modifying MySQL character set

<<:  Summary of Linux operation and maintenance from elementary to advanced knowledge points

>>:  JavaScript regular verification password strength implementation method

Recommend

CSS cleverly uses gradients to achieve advanced background light animation

accomplish This effect is difficult to replicate ...

Native JS to implement paging click control

This is an interview question, which requires the...

Nginx Location Configuration Tutorial from Scratch

Basics The matching order of location is "ma...

A brief talk about MySQL semi-synchronous replication

Introduction MySQL achieves high availability of ...

Example of how to optimize MySQL insert performance

MySQL Performance Optimization MySQL performance ...

Very practical Tomcat startup script implementation method

Preface There is a scenario where, for the sake o...

Detailed explanation of nginx configuration file interpretation

The nginx configuration file is mainly divided in...

CentOS 7 installation and configuration method graphic tutorial

This article records the detailed installation tu...

Implementation of importing and exporting docker images

Docker usage of gitlab gitlab docker Startup Comm...

TypeScript learning notes: type narrowing

Table of contents Preface Type Inference Truth va...

Example code for implementing stacked carousel effect with HTML+CSS+JS

Effect: When the slideshow moves in one direction...

React error boundary component processing

This is the content of React 16. It is not the la...

Detailed explanation of MySQL database triggers

Table of contents 1 Introduction 2 Trigger Introd...

JavaScript to achieve digital clock effects

This article example shares the specific code for...

How to set up swap partition SWAP in Linux 7.7

The Swap partition of the Linux system, that is, ...