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

Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

1. Add the plug-in and add the following configur...

js code to realize multi-person chat room

This article example shares the specific code of ...

vue-electron problem solution when using serialport

The error is as follows: Uncaught TypeError: Cann...

MYSQL uses Union to merge the data of two tables and display them

Using the UNION Operator union : Used to connect ...

37 Tips for a Good User Interface Design (with Pictures)

1. Try to use single column instead of multi-colum...

15 Vim quick reference tables to help you increase your efficiency by N times

I started using Linux for development and enterta...

Implementation steps for building multi-page programs using Webpack

It is very common to use webpack to build single-...

MYSQL string forced conversion method example

Preface Since the types of the same fields in the...

Ideas and codes for realizing magnifying glass effect in js

This article example shares the specific code of ...

js realizes the dynamic loading of data by waterfall flow bottoming out

This article shares with you the specific code of...

How to manually upgrade the node version under CentOs

1. Find the corresponding nodejs package, refer t...

React diff algorithm source code analysis

Table of contents Single Node Diff reconcileSingl...

Sample code for JS album image shaking and enlarging display effect

The previous article introduced how to achieve a ...