java mysql cp1252_关于java连接MYSQL中文乱码处理

java连接mysql中参数的中文乱码问题

1,在创建mysql数据库时,需要在mysql目录下添加my.ini文件

[mysqld]

character-set-server=utf8

#绑定IPv4和3306端口

bind-address = 0.0.0.0

port = 3306

# 设置mysql的安装目录

basedir=C:\Program Files\MySQL\MySQL Server 5.5

# 设置mysql数据库的数据的存放目录

datadir=C:\Program Files\MySQL\MySQL Server 5.5\data

# 允许最大连接数

max_connections=200

# skip_grant_tables

[mysql]

default-character-set=utf8

[mysql.server]

default-character-set=utf8

[mysql_safe]

default-character-set=utf8

[client]

default-character-set=utf8

修改完成后打开cmd  启动mysql

启动mysql

net start mysql

停止mysql

net stop mysql

启动完成后进入mysql

查看

show variables like 'character%';

AAffA0nNPuCLAAAAAElFTkSuQmCC

2,数据库字段编码格式查看

AAffA0nNPuCLAAAAAElFTkSuQmCC

3、查看 MySQL 数据表(table) 的字符集。

mysql> show table status from sqlstudy_db like '%countries%';

+-----------+--------+---------+------------+------+-----------------+------

| Name | Engine | Version | Row_format | Rows | Collation |......

+-----------+--------+---------+------------+------+-----------------+------

| countries | InnoDB | 10 | Compact | 11 | utf8_general_ci |......

+-----------+--------+---------+------------+------+-----------------+------

4、查看 MySQL 数据列(column)的字符集。

mysql> show full columns from countries;

+----------------------+-------------+-----------------+--------

| Field | Type | Collation | .......

+----------------------+-------------+-----------------+--------

| countries_id | int(11) | NULL | .......

| countries_name | varchar(64) | utf8_general_ci | .......

| countries_iso_code_2 | char(2) | utf8_general_ci | .......

| countries_iso_code_3 | char(3) | utf8_general_ci | .......

| address_format_id | int(11) | NULL | .......

+----------------------+-------------+-----------------+--------

5、查看当前安装的 MySQL 所支持的字符集。

mysql> show charset;

mysql> show char set;

+----------+-----------------------------+---------------------+--------+

| Charset | Description | Default collation | Maxlen |

+----------+-----------------------------+---------------------+--------+

| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |

| dec8 | DEC West European | dec8_swedish_ci | 1 |

| cp850 | DOS West European | cp850_general_ci | 1 |

| hp8 | HP West European | hp8_english_ci | 1 |

| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |

| latin1 | cp1252 West European | latin1_swedish_ci | 1 |

| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |

| swe7 | 7bit Swedish | swe7_swedish_ci | 1 |

| ascii | US ASCII | ascii_general_ci | 1 |

| ujis | EUC-JP Japanese | ujis_japanese_ci | 3 |

| sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 |

| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |

| tis620 | TIS620 Thai | tis620_thai_ci | 1 |

| euckr | EUC-KR Korean | euckr_korean_ci | 2 |

| koi8u | KOI8-U

6、修改表和字段的字符集

//修改数据库

mysql> alter database name character set utf8;

//修改表

alter table 表名 convert to character set gbk;

//修改字段

alter table 表名 modify column '字段名' varchar(30) character set gbk not null;

//添加表字段

alter table 表名 add column '字段名' varchar (20) character set gbk;

注:执行命令过程中字段名不加引号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值