当前位置:Gxlcms > mysql > mysql5.5乱码解决方案_MySQL

mysql5.5乱码解决方案_MySQL

时间:2021-07-01 10:21:17 帮助过:26人阅读

bitsCN.com 1、先卸载mysql5.5,将所有mysql的文件夹都删除包括注册表里的 1、HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Services/Eventlog/Application/MySQL 目录删除
2、HKEY_LOCAL_MACHINE/SYSTEM/ControlSet002/Services/Eventlog/Application/MySQL 目录删除
  3、HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Eventlog/Application/MySQL 目录删除2、重新安装mysql5.5,注意选择字符集时要选utf83、修改my.ini文件夹里的 [mysql] default-character-set=gbk4、重启服务,然后在mysql client执行下列命令查看,如果有这样的结果就OK
mysql> show variables like 'chara%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | gbk
|
| character_set_connection | gbk
|
| character_set_database | utf8
|
| character_set_filesystem | binary
|
| character_set_results | gbk
|
| character_set_server | utf8
|
| character_set_system | utf8
|
| character_sets_dir | c:/Program Files/MySQL/MySQL Server 5.0/share/chars
ets/ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
查看表的编码 >show create table person; 5、在jsp页面要如下配置 <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%> 6、在连接mysql类里要如下设置 String driverName = "com.mysql.jdbc.Driver";//"org.gjt.mm.mysql.Driver"两个驱动都可以用
String dbHost = host;//数据库的一些信息
String dbPort = port;
String dbName = dbaName;
String enCoding = "?useUnicode=true&characterEncoding=gb2312"; //解决MySql中文问题,要连续写不能空格
String userName = usName;
String Psw = psw;
String url = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName+enCoding;
try
{
Class.forName(driverName).newInstance();
dbconn = DriverManager.getConnection(url, userName, Psw);
//getConnection(url, userName, Psw)从给的driver中选择合适的去连接数据库
//return a connection to the URL
}catch(Exception e){
print("url = " + url); //发生错误时,将连接数据库信息打印出来
print("userName = " + userName);
print("Psw = " + Psw);
print("Exception: " + e.getMessage());//得到出错信息
}
if (dbconn != null)//dbconn != null 表示连接数据库成功,由异常保证!?
return true;
else
return false;bitsCN.com

人气教程排行