关于mysql数据库插入数据,不能插入中文和出现中文乱码问题

   首先,推荐一篇博客:http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html

    当时,我安装完mysql数据库后,新建一个数据库后插入数据,首先出现了中文不能插入mysql数据库的问题,解决办法如下:

    修改mysql文件中my.ini里的 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"变成sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",修改完后,重启mysql服务,即可解决中文无法插入的问题。

    接下来,可能会发现插入的中文出现了乱码问题,那么解决的办法就是,修改my.ini文件中 character-set-server=utf8和 character-set-server=utf8这两句,如果不是utf8就全部修改成utf8格式,这样再次重启mysql服务即可解决插入中文乱码的问题。(PS:这里又会出现一个新问题,那就是在之前已经创建的数据库,此时插入中文可能也会出现中文乱码,解决的办法就是删除原来创建的数据库,重新创建一个一模一样的数据库,就不会出现插入中文乱码的问题啦。或者删除对应的表,重新创建该表。直接修改表的字符集也是不行,必须删除表。)

 具体修改完后的my.ini文件如下(此处是我自己的mysql中my.ini文件,仅作参考哦):

   

复制代码

####################配置文件开始###################

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


 

 [mysqld]

 character-set-server=utf8

 port=3306

 basedir  ="F:\mysql/"

 datadir  ="F:\mysql/data/"

 tmpdir   ="F:\mysql/data/"

 socket   ="F:\mysql/data/mysql.sock"

 log-error="F:\mysql/data/mysql_error.log"

 

 #server_id = 2


 #skip-locking

 

 max_connections=100

 table_open_cache=256

 query_cache_size=1M

 

 tmp_table_size=32M

 thread_cache_size=8

 

 innodb_data_home_dir="F:\mysql/data/"

 innodb_flush_log_at_trx_commit =1

 innodb_log_buffer_size=128M

 innodb_buffer_pool_size=128M

 innodb_log_file_size=10M

 innodb_thread_concurrency=16

 innodb-autoextend-increment=1000

 join_buffer_size = 128M

 sort_buffer_size = 32M

 read_rnd_buffer_size = 32M

 max_allowed_packet = 32M

 explicit_defaults_for_timestamp=true

 sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

 #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

####################配置文件结束###################
发布了48 篇原创文章 · 获赞 38 · 访问量 25万+
展开阅读全文

mysql 插入数据中文乱码

04-08

我用navicat写的插入数据这样的话会失败,乱码。数据库和表的编码都是utf8的。后来我换了一种方法就成功了,就是改成了 insert into Student values('01' , '赵雷' , '1990-01-01' , '男'), ('02' , '钱电' , '1990-12-21' , '男'), ('03' , '孙风' , '1990-05-20' , '男'), ('04' , '李云' , '1990-08-06' , '男'), ('05' , '周梅' , '1991-12-01' , '女'), ('06' , '吴兰' , '1992-03-01' , '女'), ('07' , '郑竹' , '1989-07-01' , '女'), ('08' , '王菊' , '1990-01-20' , '女'); 以下是错误的以及提示,不懂为什么,版本的问题么 mysql> insert into Student values(04 , '李云' , '1990-08-06' , '男'); insert into Student values(05 , '周梅' , '1991-12-01' , '女'); insert into Student values(06 , '吴兰' , '1992-03-01' , '女'); insert into Student values('07' , '郑竹' , '1989-07-01' , '女'); insert into Student values('08' , '王菊' , '1990-01-20' , '女'); Query OK, 1 row affected 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''濂?)' at line 1 mysql> delete table student; 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table student' at line 1 mysql> drop table student; Query OK, 0 rows affected ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览