【史上最坑】MYSQL插入数据时中文乱码的发生和解决,一个容易忽略的细节

最近往数据库里查数据,发现插入的数据全都是???的情况。

遇到这种一般的第一反应就是,数据库乱码了。于是便开始去解决数据库乱码:

1.首先检查链接问题,配置文件中是否设置了编码

serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false

 配置文件中有写,那么这个地方忽略继续寻找。

2.检查数据库配置文件my.ini中是否有设置编码 (我用docker安装的镜像)

        2.1首先进入容器:

docker exec -it 27c792ca2ab5 /bin/bash  (27c792ca2ab5 为CONTAINER ID)

        2.2查看配置文件:(路径注意 有些人的是 、..mysql/mysql.conf.d/..  我的是..mysql/conf.d/.. )

more /etc/mysql/conf.d/mysqld.cnf

没有配置东西???那就是你了,这下跑不掉了。 来,给你加上

# Copyright (c) 2015, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysql]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character_set_server=utf8
init_connect='SET NAMES utf8'
max_allowed_packet = 20M

[mysql]
default-character-set = utf8

[mysql.server]
default-character-set = utf8

[mysqld_safe]
default-character-set = utf8

[client]
default-character-set = utf8

加上之后满怀信心,这下应该可以了。满意,nice。

what  fuck !!!  什么情况!!!

 

 现在从哪下手???有事找度娘,各种搜。结果发现,这个地方被忽略了

=》打开Navica> 编辑链接>高级>编码> 查看你的编码是否为自动 若不是设置成自动。

我丢! 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值