java insert mysql 中文乱码
jdbc:mysql://192.168.1.77:3306/db360?useUnicode=true&characterEncoding=UTF-8
drop database if exists ljdb; create database ljdb character set 'utf8' collate 'utf8_general_ci'; use ljdb; drop table if exists rinfo; create table rinfo( day varchar(30) ,id bigint ,abc varchar(30) ,addr1 varchar(30) ,addr2 varchar(30) ,abcd decimal(5,2) ,cc decimal(5,2) ,dd bigint ,eee bigint ,fff varchar(30) ,mask varchar(30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; CREATE USER 'abc'@'%' IDENTIFIED BY 'abc123'; grant all privileges on ljdb to abc@'%'; grant all on *.* to abc@'%';
修改my.ini配置文件
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
修改MySql默认编码
MySql默认编码是Latin1,不支持中文,要想修改默认编码,需要修改my.ini文件
[client]增加default-character-set=utf8
[mysql]增加default-character-set=utf8
[mysqld]增加
character_set_server=utf8
init_connect='SET NAMES utf8'
ref: https://blog.csdn.net/kakarot5/article/details/40088137
mysql> show variables like 'char_%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec) mysql> set names utf8; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'char_%'; +--------------------------+----------------------------+ | 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 | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)