>show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
从以上信息可知数据库的编码为latin1,需要修改为gbk或者是utf8;第一步打开mysql软件,输入密码,按下回车键,如下图所示:
第二步在命令行先输入"use day14_customer;",按回车键,进去数据库,注意最后一个分号,day14_customer是数据库名字,如下图所示:
第三步再输入“ show create database day14_customer;”,查看数据库的编码方式
4
第四步修改数据库编码信息,输入“alter database day14_customer default character set gbk;”补充。。。。select from information_schemacharacter_sets;select from information_schemacollations;select from information_schemacollation_character_set_applicability;mysql> show variables like “character_set_%”;
+————————–+—————————-+
| 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 |
修改mysql的myini文件中的字符集
default-character-set = utf8
character_set_server = utf8可以通过以下方法来进行编码格式判断,输入一个字符串,之后返回字符串编码类型。
public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (strequals(new String(strgetBytes(encode), encode))) { //判断是不是GB2312
String s = encode;
return s; //是的话,返回“GB2312“,以下代码同理
}
} catch (Exception exception) {
}
encode = "ISO-8859-1";
try {
if (strequals(new String(strgetBytes(encode), encode))) { //判断是不是ISO-8859-1
String s1 = encode;
return s1;
}
} catch (Exception exception1) {
}
encode = "UTF-8";
try {
if (strequals(new String(strgetBytes(encode), encode))) { //判断是不是UTF-8
String s2 = encode;
return s2;
}
} catch (Exception exception2) {
}
encode = "GBK";
try {
if (strequals(new String(strgetBytes(encode), encode))) { //判断是不是GBK
String s3 = encode;
return s3;
}
} catch (Exception exception3) {
}
return ""; //如果都不是,说明输入的内容不属于常见的编码格式。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)