解决mysql中文乱码(三个地方要注意):_MySQL
May 27, 2016 pm 02:12 PMbitsCN.com 1.查看mysql字符集
SHOW VARIABLES LIKE'character_set_%';
设置字符集命令:SETcharacter_set_client='utf8';
2.新建的数据库和表的字符编码都是utf8
3.代码中连接数据库的字符编码
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://192.168.99.122:3306/mtime123?user=root&password=root123&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false");
其实只要做到字符编码统一并且支持中文就可以了,但是有时候我们发现尽管我们做到了以上三点还是会乱码,在程序中会报错某个字段的值是一串二进制编码,原因是该字段没有统一编码,不是utf8。。。。
将数据库结构导出成sql文本,然后打开检查里面的数据库,表和每个字段是否是utf8(只要做到统一编码就行),如果不是就改过来。
DROP TABLE IF EXISTS `award`;CREATE TABLE `award` ( `id` bigint(32) unsigned NOT NULL AUTO_INCREMENT, `award_content` longtext CHARACTER SET utf8, `movie_id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP?

What are the application scenarios of Java enumeration types in databases?

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP?

Performance optimization strategies for PHP array paging
