关于mysql数据库插入数据,不能插入中文和出现中文乱码问题
??? 首先,推薦一篇博客:http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html
??? 當(dāng)時,我安裝完mysql數(shù)據(jù)庫后,新建一個數(shù)據(jù)庫后插入數(shù)據(jù),首先出現(xiàn)了中文不能插入mysql數(shù)據(jù)庫的問題,解決辦法如下:
??? 修改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服務(wù),即可解決中文無法插入的問題。
??? 接下來,可能會發(fā)現(xiàn)插入的中文出現(xiàn)了亂碼問題,那么解決的辦法就是,修改my.ini文件中 character-set-server=utf8和 character-set-server=utf8這兩句,如果不是utf8就全部修改成utf8格式,這樣再次重啟mysql服務(wù)即可解決插入中文亂碼的問題。(PS:這里又會出現(xiàn)一個新問題,那就是在之前已經(jīng)創(chuàng)建的數(shù)據(jù)庫,此時插入中文可能也會出現(xiàn)中文亂碼,解決的辦法就是刪除原來創(chuàng)建的數(shù)據(jù)庫,重新創(chuàng)建一個一模一樣的數(shù)據(jù)庫,就不會出現(xiàn)插入中文亂碼的問題啦)
具體修改完后的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=utf8port=3306basedir ="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-lockingmax_connections=100table_open_cache=256query_cache_size=1Mtmp_table_size=32Mthread_cache_size=8innodb_data_home_dir="F:\mysql/data/"innodb_flush_log_at_trx_commit =1innodb_log_buffer_size=128Minnodb_buffer_pool_size=128Minnodb_log_file_size=10Minnodb_thread_concurrency=16innodb-autoextend-increment=1000join_buffer_size = 128Msort_buffer_size = 32Mread_rnd_buffer_size = 32Mmax_allowed_packet = 32Mexplicit_defaults_for_timestamp=true sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES####################配置文件結(jié)束###################?
總結(jié)
以上是生活随笔為你收集整理的关于mysql数据库插入数据,不能插入中文和出现中文乱码问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PowerDesigner逆向生成
- 下一篇: 数据库SQL及相关