[Database] Mac environment solves the problem that MySQL cannot insert Chinese

After reading a lot of tutorials, I finally got it done.
Reference:
https://blog.csdn.net/vr_jia/article/details/71891515
http://www.cnblogs.com/mojita/p/5347614.html
1. Go to the /etc directory, use sudo to create a my.cnf file and enter:

[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8

:wq save

Last login: Wed May  2 20:31:19 on ttys000
Peggys-MacBook-Air:~ Peggy$ cd /etc
Peggys-MacBook-Air:etc Peggy$ sudo vi my.cnf
Password:
  1. Log in to mysql and check the code in status
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status;
--------------
/usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.7.21, for macos10.13 (x86_64) using  EditLine wrapper

Connection id:      13
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.21 MySQL Community Server (GPL)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8 //**特别这里**
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /tmp/mysql.sock
Uptime:         26 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.192
--------------

mysql> create database SCHOOL4;
Query OK, 1 row affected (0.00 sec)

mysql> 
  1. The modification is successful, try adding it to the table in the database
    write picture description here
    write picture description here
  2. success.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325227675&siteId=291194637