MySQL 表与字段编码格式报错
MySQL 表与字段编码格式报错
一、数据库,表,字段编码格式都为latin1(iso-8859-1) 。当数据保存到数据库后,中文显示乱码。
解决办法:
1.在访问数据库连接串中添加编码格式:
<add key="MySqlConnectionString" value="Server=127.0.0.1;Port=3306;Uid=ttt;Pwd=ttt;Database=test_db;innercharacterset=gb2312;charset=gb2312" />
获取出来的中文信息没有问题。
注意:使用gb2312编码添加的中文信息,读取时也要使用相同编码格式,也就是存取的编码格式要一致;否则获取出来为乱码。
二、若获取的字符串为Latin1编码,在C#中可以做如下转换:
/// <summary>
/// Latin1(iso-8859-1) 转 gb2312 中文
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Latin1ToUtf8( string str) {
//这里的 gb2312 取决于 mysql连接字符串中设定的字符编码。
return Encoding.GetEncoding("gb2312").GetString(Encoding.GetEncoding("ISO-8859-1").GetBytes(str));
}
MySQL 表与字段编码格式报错的更多相关文章
- Mysql表创建外键报错
数据库表A: CREATE TABLE task_desc_tab ( id INT(11) PRIMARY KEY NOT NULL COMMENT '自增主键' AUTO_INCREMENT, t ...
- Sqoop- sqoop将mysql数据表导入到hive报错
sqoop将mysql数据表导入到hive报错 [root@ip---- lib]# sqoop import --connect jdbc:mysql://54.223.175.12:3308/gx ...
- 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES
在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as cra ...
- DB2读取CLOB字段-was报错:操作无效:已关闭 Lob。 ERRORCODE=-4470, SQLSTATE=null
DB2读取CLOB字段-was报错:操作无效:已关闭 Lob. ERRORCODE=-4470, SQLSTATE=null 解决方法,在WAS中要用的数据源里面配置连个定制属性: progressi ...
- egg 连接 mysql 的 docker 容器,报错:Client does not support authentication protocol requested by server; consider upgrading MySQL client
egg 连接 mysql 的 docker 容器,报错:Client does not support authentication protocol requested by server; con ...
- MySql表、字段、库的字符集修改及查看方法
这篇文章主要介绍了MySql表.字段.库的字符集修改及查看方法,本文分别给们它的修改及查看语句,需要的朋友可以参考下 修改数据库字符集: 代码如下: ALTER DATABASE db_name DE ...
- ES使用text类型字段排序报错
elasticsearch text字段排序报错解决使用elasticsearch 进行排序的时候,我们一般都会排序数字.日期.但是在排序text类型的时候就会出现错误. GET xytest/sut ...
- mysql 中modify和change区别(以及使用modify修改字段名称报错)
使用modify修改字段报错如下: mysql> alter table student modify name sname char(16);ERROR 1064 (42000): You h ...
- mysql|full join 多表联查,系统报错,无法解答!
查询语句: select 分数 from cfull join don c.姓名=d.姓名 报错: [Err] 1054 - Unknown column 'c.姓名' in 'on clause' ...
随机推荐
- html5大纲
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDU5331 : Simple Problem
因为是二分图,所以最大独立集$=$总点数$-$最大匹配. 因为是树,所以具有贪心性质,设$f_i$表示$i$是否与其孩子匹配,$a_i$表示$i$的孩子里$f$为$0$的个数,则$f_i=[a_i&g ...
- HDU5735 : Born Slippy
考虑DP,设$f[x]$表示最后一个是$x$时的最优解,则$f[x]=\max(f[y]+w[x]\ opt\ w[y])$,其中$y$是$x$的祖先. 注意到$w[i]<2^{16}$,那么将 ...
- QWord2vec:word2vec移植版+GUI
序 Word2Vec原生是不支持Windows的,索性就用Qt移植了一下. 大概做了下面几件事. ①替换LinuxAPI的pthread为QThread. ②取消了posix_memalign(),内 ...
- sed 格式化输出df -h
df -h|sed '1d;/ /!N;s/\n//;s/ \+/ /;' 1d——————删除第一行 / /!N——————没有空格的行执行N 例子中没有空格的行 /dev/mapper/vg_ds ...
- [Leetcode] Word BreakII
Question: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence w ...
- 【BZOJ1001】【BeiJing2006】狼抓兔子 最大流
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...
- BZOJ4546: codechef XRQRS
Description 给定一个初始时为空的整数序列(元素由1开始标号)以及一些询问: 类型1:在数组后面就加入数字x. 类型2:在区间L…R中找到y,最大化(x xor y). 类型3:删除数组最后 ...
- java-常见异常
一.运行时异常 1.空指针(java.lang.NullPointerException) 2.类型转换() 3.数组下标越界(java.lang.ArrayIndexOutOfBoundsExcep ...
- 快速安装zabbix agent并部署监控
1.准备yum源: epel源:yum install -y zabbix22-agent 2.上传脚本: 上传脚本事先写好的监控脚本到/script/下面 3.修改配置文件:Server=10.10 ...