mysql> show variables like '%chara%';
+--------------------------+----------------------------+
| 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 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> show global variables like '%chara%';
+--------------------------+----------------------------+
| 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 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
在服务器里面的命令行查询数据没有问题,但是在程序中查询的数据中文乱码。 麻烦 v 友帮忙看看。
1
pubby 2016-12-20 23:03:01 +08:00 1
set names utf8;
|
2
pubby 2016-12-20 23:03:28 +08:00
新版建议直接用 utf8mb4
|
3
adrianzhang 2016-12-20 23:17:21 +08:00
my.cnf 里要设置 utf8
|
4
Miy4mori 2016-12-20 23:19:39 +08:00 via Android
检查下 connection url ?
|
5
tigerstudent 2016-12-20 23:45:21 +08:00 via Android
熟悉的坑。。
|
6
chiv2 2016-12-21 01:49:33 +08:00
一个里面装满了新手程序员的坑。
|
7
pouta 2016-12-21 08:16:00 +08:00 via Android
如果有中文 除了设置编码 查询或写入数据之前都要执行这条 sql 语句 set names utf8(一个新手程序员,有错请指正,谢谢)
|
8
sundyandy 2016-12-21 09:43:57 +08:00
确保你后端语言(假设是 php )连接时用的编码也是 utf8 。。
|
9
Joban OP 这个设置了
|
10
Joban OP @adrianzhang 在 my.cnf 也设置了
|
11
Joban OP <property name="url" value="jdbc:mysql://...:3306/jewelty?useUnicode=true&characterEncoding=utf-8" />
url 我是这样写的,有没有问题? |
12
Joban OP 已解决。
修改了列的的字符集 ALTER TABLE table MODIFY column TEXT [...] CHARACTER SET utf8; |
13
aiyo218 2016-12-26 19:38:16 +08:00
建表没设字符集?
|