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

Why is the scroll bar on the web page set on the right?

Why are the scroll bars of the browsers and word ...

Solution to Ubuntu cannot connect to the network

Effective solution for Ubuntu in virtual machine ...

6 interesting tips for setting CSS background images

Background-image is probably one of those CSS pro...

Troubleshooting ideas and solutions for high CPU usage in Linux systems

Preface As Linux operation and maintenance engine...

Vue+js click arrow to switch pictures

This article example shares the specific code of ...

Mysql database scheduled backup script sharing

BackUpMysql.sh script #!/bin/bash PATH=/bin:/sbin...

How to view the network routing table in Ubuntu

What are Routing and Routing Table in Linux? The ...

The best 9 foreign free picture material websites

It is difficult to find good image material websi...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

Detailed steps for installing Harbor, a private Docker repository

The installation of Harbor is pretty simple, but ...

CSS perfectly solves the problem of front-end image deformation

I saw an article in Toutiao IT School that CSS pe...