zoukankan      html  css  js  c++  java
  • 解决Django在mariadb创建的表插入中文乱码的问题

    1.确保你的mariadb数据库的character_set_connection、character_set_database、character_set_server的编码均为utf8

    MariaDB [(none)]> show variables like "character_set_%";
    +--------------------------+----------------------------+
    | 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/share/mysql/charsets/ |
    +--------------------------+----------------------------+


    2.如果mariadb数据库不是UTF,请修改以下配置文件的项
    /etc/my.cnf
    [mysqld]
    character-set-server=utf8

    [mysql]
    default-character-set=utf8

    [client]
    default-character-set=utf8

    /etc/my.cnf.d/server.cnf
    [mysqld]
    init_connect = 'SET NAMES utf8'
    character-set-server = utf8

    3.确保创建的数据库编码格式为utf-8
    MariaDB [(none)]> show create database django_demo1;
    +--------------+-----------------------------------------------------------------------+
    | Database | Create Database |
    +--------------+-----------------------------------------------------------------------+
    | django_demo1 | CREATE DATABASE `django_demo1` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    +--------------+-----------------------------------------------------------------------+
    1 row in set (0.01 sec)

    如果不是,则新建一个编码格式为utf-8的数据库
    CREATE DATABASE django_demo1 DEFAULT CHARACTER SET utf8

  • 相关阅读:
    HTML 基础 元素 标签
    HTML5 元素介绍
    网站程序 模板下载 下载 ftp
    域名解析和空间绑定
    如何选择云虚拟主机操作系统?
    网站备案查询
    响应式网站01
    项目中使用百度统计和友盟统计
    项目中使用http referer,为了盗取图片资源
    vue-awesome-swiper中的数据异步加载
  • 原文地址:https://www.cnblogs.com/liangjiongyao/p/9238974.html
Copyright © 2011-2022 走看看