mysql:Incorrect string value: '\xE5\xA4\xA7\xE8\xBF\x9E' for column '' at row 1

Mysql默认字符集:
在Mysql的安装根目录下,my.ini中:

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf-8
     安装时,默认的字符集是latin1.
    Mysql默认字符集,可以在安装时配置,也可以通过Mysql自带的MySQL Server Instance Config Wizard重新配置,配置后重启服务才可生效。

终端登录mysql 后输入
show variables like '%char%';

可以显示该数据库连接使用的字符集的情况,
你会发现,有几个字符集用的是.安装时,默认的字符集是latin1.
或者其他不兼容中文的字符集

如何设置默认编码为utf8

  1. 进入到/usr/local/mysql/support-files
    目录。里面有个文件:my-default.cnf

有的系统环境或者最近新版的mysql环境里可能没有my-default.cnf,请直接进行2操作

  1. 改名为my.cnf, 其内容改为。
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
default-character-set=utf8
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
port        = 3306
socket      = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id   = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout`
  1. 将修改后的文件my.cnf
    复制到 /etc 目录下。

4.重启mysql服务

终端登录mysql 后输入
show variables like '%char%';
查看一下字符集的使用情况

使用 navicat 等图像管理工具,更改字符集

更改数据库字符集
更改完成
更改表的字符集
更改表的默认字符集完成
更改字段的字符集

参考: http://www.jianshu.com/p/362ca4b4e412

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • From: 博客园 Johney最近,在项目组使用的mysql数据库中,插入数据出现乱码,关于这个问题做了下总结...
    zheng7阅读 4,505评论 1 2
  • 转自: http://www.laruence.com/2008/01/05/12.html 略有修改 基本概念 ...
    布丁芝麻糊糊阅读 4,635评论 1 1
  • 前段时间公司内部博客上凯哥分享了一篇关于mysql字符集编码的文章,之前我对mysql字符集一块基本没有深究过,看...
    __七把刀__阅读 11,584评论 14 18
  • 夜深了,窗外小区路上夜行的车辆还是不间断,车轮碾压路面的摩擦声分外清晰,对面高楼上还有未熄的灯光透出,甚至能感觉出...
    移影上花梢阅读 2,962评论 0 0
  • 我知道,我要不趁着现在在气头上我后期是什么也不会写的。 首页有一文章,大意说我们这样期待六小龄童前辈上春晚,是一帮...
    漫漫无忧阅读 1,924评论 9 2