情景
在centos下部署flask项目,使用的是mariadb,(本地mysql香香的),用到sqlarchemy,插入前中文,出入后查询乱码,最终定位在数据库上,
排查
代码语言:javascript复制mysql>show variables like 'character%';
创建时定义好数据库字符
代码语言:javascript复制//这里创建一个名为BEvents的数据库
create database BEvents default charset utf8 collate utf8_general_ci;
代码语言:javascript复制MariaDB [BEvents]> show variables like 'character%';
-------------------------- ----------------------------
| 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/ |
-------------------------- ----------------------------
8 rows in set (0.01 sec)