解决mysql数据库中文乱码问题
解决乱码最好的方法是在项目设计之初,统一所有的字符集,例如页面、request对象以及数据库等等。
一、 几种常见的乱码现象:
1、页面乱码
单纯的页面乱码是很好解决的,只要修改头部适合的字符集即可,如果页面中文显示乱码,你可以把字符集修改为:gb2312或gbk。
2、页面之间传递的参数是乱码
页面之间传递参数出现的乱码,就要解决页面编码和requset的字符集问题,在参数传进传出时重新设置相应的字符集。比如:request.setCharacterEncoding("UTF-8");
3、数据库乱码(下面详细介绍)
在ssh框架中解决中文乱码问题(希望对你有用!)
1. jsp页面中 全部为utf-8
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2.action中为utf-8(有时有作用)
HttpServletRequest request =ServletActionContext.getRequest();
request.setCharacterEncoding("UTF-8");
3. web.xml中为utf-8
<!-- Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter- class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
4.数据库连接为utf-8
jdbc:mysql://localhost/数据库名?useUnicode=true&characterEncoding=UTF-8
5 数据库编码为gbk(见附件)
页面和页面传值都没有问题,结果发现存储在数据库中的数据出现了乱码,则问题是出现在数据库的编码问题。
下面我已MySql数据库为例说明解决方法:
如果你安装数据库的时候字符集使用的默认选项:latin1
DOS命令下进入数据库show 一下字符集(命令:show variables like"%char%"; )
相关文档:
我的测试环境.基本上数据是瞬间同步,希望对大家有帮助
redhat 9.0
mysql3.23.57
mysql数据同步备份
A服务器: 192.168.1.2 主服务器master
B服务器: 192.168.1.3 副服务器slave
A服务器设置
#mysql –u root –p
mysql>GRANT FILE ON *.* TO backup@192.168.1 ......
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE 9.2, 9.3, 10.0 & 10.1 operating systems, but most of the steps ought to be valid for all Linux-lik ......
how to install apache, PHP and MySQL on Linux
This tutorial explains the installation of Apache web server, bundled
with PHP and MySQL server on a Linux machine. The tutorial is primarily for SuSE
9.2, 9.3, 10.0 & 10.1, but most of the steps ought to be valid for all
Linux-like operating ......
虽然说我们尽量在写程序的时候控制插入到数据库的数据,而不要用数据库去判断数据的对错,但是有时候为了方便还是需要数据库自身的容错能力来帮助我们达到目的的。举例说明:
创建如下数据表
CREATE TABLE `book` (
`id` int(11) default NULL,
`num` int(11) unsigned default NULL
) ENGINE=InnoDB DE ......
今天找到了取mysql表和字段注释的语句
取字段注释
SELECT COLUMN_NAME 列名, DATA_TYPE 字段类型, COLUMN_COMMENT 字段注释
from INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'companies'##表名
AND table_schema = 'testhuicard'##数据库名
AND column_name LIKE 'c_name'##字段名
--------------------------- ......