django-vue-admin 使用Mariadb 连接提示Character set ‘utf8‘ is not a compiled character set解决

git 后,使用 python3 manage.py makemigrations 提示如下:

Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
!
Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
!
Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
/home/python/env/dvdmin/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py:105: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': (2019, "Can't initialize character set utf8 (path: /usr/share/mysql/charsets/)")
  warnings.warn

python3 manage.py migrate

Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
!
Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
!
Character set 'utf8' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file

按照网上说的,修改相应配置:

mariadb-secure-installation

设置MariaDB字符集. 需要设置4个文件my.cnf, client.cnf, mysql-clients.cnf, server.cnf.

1 vim /etc/my.cnf 增加以下内容

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

2 vim /etc/my.cnf.d/client.cnf 在[client]后增加 default-character-set=utf8

[client]
default-character-set=utf8mb4

3 vim /etc/my.cnf.d/mysql-clients.cnf在[mysql]增加default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

4 vim /etc/my.cnf.d/server.cnf 在[server]后增加character-set-server=utf8mb4

[server]
character-set-server=utf8mb4

 重启MariaDB, 连接数据库,检查字符集.

1 重启MariaDB

systemctl restart mariadb

2 连接数据库.

# 回车输入密码即可
mysql -uroot -hlocalhost -P3306 -p

3 检查字符集

show variables like "%character%";
show variables like "%collation%";

没什么卵用!

停下来分析了一下,是不是与pymqsql有关:

在dvadmin\system\_init_.py中加入下面两行:

import pymysql

pymysql.install_as_MySQLdb()

 

 顺利通过!

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值