首先,针对mysql数据库来说,它的默认字符是:latin1
我们写不进去中文的罪魁祸首就是这个latin1。那么,对应的解决办法就是将这个字符集改成UTF-8
那么,最简便的方法:对于window(修改my.ini配置文件),my.ini在哪里,如何修改成UTF-8如下:
https://www.cnblogs.com/Ray-xujianguo/p/3322455.html
对于mac平台(修改/etc/my.cnf配置文件),但事实却是我们在/etc下面没有my.cnf配置文件。这时候就要我们自己写一个my.cnf配置文件支持UTF-8
我们用vim 在/etc路径下新建一个my.cnf(记得用sudo命令哦),
sudo vim my.cnf
然后将如下代码拷贝到my.cnf里面:
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific