MySQL配置的JDBC URL使用utf8字符编码

回答:

我已/etc/mysql/my.cnf手动配置使用utf8。见下文:

[mysqld]

character-set-server=utf8

character-sets-dir=/usr/share/mysql/charsets

[mysql]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqladmin]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlcheck]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqldump]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlimport]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[mysqlshow]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

[client]

character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8

从控制台:

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 | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

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

8 rows in set (0.01 sec)

回答:

现在,对于网络应用程序,我在Tomcat的 context.xml

url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"

url="jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=utf8&connectionCollation=utf8_general_ci"

上面的方法不起作用,并为我提供了以下应用程序。

show variables like 'char%';

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

| Variable_name | Value |

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

| character_set_client | utf8mb4 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8mb4 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

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


这里可能出什么问题了?为什么它显示utf8mb4代替utf8

回答:

您可能需要执行以下操作:

MySQL Connector / J

5.1.13中的更改(2010-06-24)

  • Connector / J不支持服务器5.5.2和更高版本的utf8mb4。

现在,Connector /

J会自动检测配置有服务器的服务器,character_set_server=utf8mb4或者将其characterEncoding=...视为utf8mb4SET

NAMES=建立连接时使用的调用中所传递的Java编码utf-8 。错误#54175)

以上是 MySQL配置的JDBC URL使用utf8字符编码 的全部内容, 来源链接: utcz.com/qa/433759.html

回到顶部