Home Database Mysql Tutorial 解决mysql中文乱码(三个地方要注意):_MySQL

解决mysql中文乱码(三个地方要注意):_MySQL

May 27, 2016 pm 02:12 PM
mysql Chinese

bitsCN.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;
Copy after login
bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into a MySQL table using PHP?

What are the application scenarios of Java enumeration types in databases? What are the application scenarios of Java enumeration types in databases? May 05, 2024 am 09:06 AM

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 fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

How to use MySQL stored procedures in PHP?

Performance optimization strategies for PHP array paging Performance optimization strategies for PHP array paging May 02, 2024 am 09:27 AM

Performance optimization strategies for PHP array paging

See all articles