mysql应用学习-解决数据乱码

原因

mysql数据库character_set_database和character_set_server默认编码是latin1,所以导致乱码;

修改步骤

step1. 修改my.ini配置

  在[mysqld]组下添加character_set_server=utf8;我的配置:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/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.

[mysqld]

# 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 = .....

basedir=D:/mysql-5.6.20-winx64
datadir=D:/mysql-5.6.20-winx64/data
character-set-server=utf8
#character-set-connection=utf8
#character-set-results=utf8

# 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

[mysql]


[client]
View Code

step2. 重新启动mysql服务

  输入命令:net stop mysql

  停止服务后,

  输入命令:net start mysql

step3. 查看修改结果

  重启mysql服务后,进入mysql,

  输入命令:show variables like 'character%';

  显示结果:

  

  这时以文本形式插入数据,显示正常:

  

其他

  在这提一下default_character_set,它在mysql5.5.3中已移除,详情请看--default-character-set=charset_name

 

posted @ 2015-01-11 20:01  paulhe  阅读(474)  评论(0编辑  收藏  举报
friendster counter