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%";

django-vue-admin 使用Mariadb 连接提示Character set ‘utf8‘ is not a compiled character set解决_第1张图片

没什么卵用!

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

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

import pymysql

pymysql.install_as_MySQLdb()

 

 顺利通过!

你可能感兴趣的:(django,mariadb,python)