mybatis + mysql + mac navicat 中文乱码问题
2016-12-08 20:54
316 查看
mybatis + mysql + mac navicat 中文乱码问题
mybatis mysql mac navicat 中文乱码问题mybatis
a配置文件
bwebxml
mysql
建表语句
配置文件
navicat
如果以上任何地方出现中文乱码,请对照如下先后顺序,一一查看。
1.mybatis
a.配置文件:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- development:开发模式 work:工作模式 --> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/youdatabasename?characterEncoding=utf-8"/> <property name="username" value="root"/> <property name="password" value="1234"/> </dataSource> </environment> </environments> <mappers> <mapper class="com.youpackage.DataMapper"/> </mappers> </configuration>
注意上面的url属性,后面只需要加
characterEncoding=utf-8,多余的先删掉。
b.web.xml
过滤器配置<filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2.mysql
建表语句:
CREATE TABLE `user` ( `id`........ PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
注意结尾设置utf8,这里使用的是utf8mb4,支持emoji表情。
配置文件
osx的配置文件在/usr/local/mysql-5.7.16-osx10.11-x86_64/support-files中,文件名为
my-default.cnf(windows中为
my.ini,linux中为
my.cnf),这个文件不可编辑,首先,复制到文稿中,然后编辑。
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
全文替换即可,如果你的不是utf8mb4,那就把这个改成utf8。
navicat
编辑Connection属性为Auto即可。
相关文章推荐
- Mac 下 MySQL 5.7 连接 navicat 中文乱码问题终极解决方案
- 【MySQL for Mac】navicat for mysql中文乱码问题——MySQL在Mac的字符集设置
- Mac中安装与配置Mysql+Navicat中文乱码问题
- 解决springmvc+mybatis+mysql中文乱码问题
- 在MAC下 Mysql 插入中文记录出现问号乱码的问题
- 解决springmvc+mybatis+mysql中文乱码问题【转】
- 解决mac下MySQL插入中文显示乱码的问题
- mysql在mac笔记本下解决中文乱码问题 并且 在mac下怎么启动和终止mysql服务
- mysqldump以及navicat导出mysql脚本中文乱码的问题--自己记录依稀
- 解决springmvc+mybatis+mysql中文乱码问题【转】
- 解决springmvc+mybatis+mysql中文乱码问题
- MyBatis操作MySQL中文乱码问题
- 【SSM】解决springmvc+mybatis+mysql中文乱码问题
- 解决springmvc+mybatis+mysql中文乱码问题【转】
- Navicat for mysql 显示中文乱码问题
- mac下解决mysql出现中文乱码问题
- Navicat for mysql 中文乱码问题
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- mac解决mysql中文乱码问题
- Navicat for MySQL中文乱码问题