到目录
在dotnetcore里,链接mysql数据,插入中文时出现没法识别,并提示插入失败的状况,分析后得知它是编码问题,即数据库编码问题,你的中文在数据表里没法被识别!html
进行mysql控制台mysql
mysql -u root -p
执行下面语句便可sql
set character_set_client = utf8; set character_set_server = utf8; set character_set_connection = utf8; set character_set_database = utf8; set character_set_results = utf8; set collation_connection = utf8_general_ci; set collation_database = utf8_general_ci; set collation_server = utf8_general_ci;
创建数据库或者修改数据库的编码为utf8便可数据库
create database dbname character set utf8; 修改数据库编码的命令为: alter database dbname character set utf8;
修改mysql配置文件,而后再重启mysql的服务便可编码
vi /etc/my.cnf --在 [mysqld] 标签下加上如下内容: default-character-set = utf8 character_set_server = utf8 --在 [mysql] 标签下加上一行 default-character-set = utf8 --在 [mysql.server]标签下加上一行 default-character-set = utf8 --在 [mysqld_safe]标签下加上一行 default-character-set = utf8 --在 [client]标签下加上一行 default-character-set = utf8
但愿本文章能够帮到各位!
到目录code