关于mysql了中的中文乱码问题
在实际开发的过程中,我要用到数据库,对于小型的项目,我们一般采用mysql数据库就可以,但是不知道大家有没有发现,在操作mysql数据库的时候,经常会出现乱码的问题。
1.表中有数据,但是查询时,显示不出来。
出现这种情况的时候,一般是写入数据和读取数据的编码格式不一致。
mysql数据库的默认编码格式是latin1,为了方便,我们一般将mysql的默认编码格式统一设置成utf8的格式。
2.插入中文数据报错
如果要插入中问的话,必须先设置:set names gbk,否则是不能插入成功的。
3.修改mysql的配置文件my.ini
mysql配置文件 my.ini 设置其字符集为gbk (重启有效)
[code="ini配置文件"]#
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/Program Files/MySQL/MySQL Server 5.1/"
#Path to the database root
datadir="D:/Program Files/MySQL/MySQL Server 5.1/Application Data/Data/"
# 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=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB