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

  • 相关阅读:
    Python Twelfth Day
    Python Tenth Day
    Python Ninth Day
    Python Eighth Day
    Python Seventh Day
    Python Sixth Day
    Python Fifth Day
    Python Fourth Day
    Python Third Day
    金融量化分析-python量化分析系列之---使用python的tushare包获取股票历史数据和实时分笔数据
  • 原文地址:https://www.cnblogs.com/liangjiongyao/p/9238974.html
Copyright © 2011-2022 走看看