首先,推薦一篇博客:http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.htmlhtml
當時,我安裝完mysql數據庫後,新建一個數據庫後插入數據,首先出現了中文不能插入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服務,便可解決中文沒法插入的問題。sql
接下來,可能會發現插入的中文出現了亂碼問題,那麼解決的辦法就是,修改my.ini文件中 character-set-server=utf8和 character-set-server=utf8這兩句,若是不是utf8就所有修改爲utf8格式,這樣再次重啓mysql服務便可解決插入中文亂碼的問題。(PS:這裏又會出現一個新問題,那就是在以前已經建立的數據庫,此時插入中文可能也會出現中文亂碼,解決的辦法就是刪除原來建立的數據庫,從新建立一個如出一轍的數據庫,就不會出現插入中文亂碼的問題啦)數據庫
具體修改完後的my.ini文件以下(此處是我本身的mysql中my.ini文件,僅做參考哦):socket
####################配置文件開始################### # 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 ####################配置文件結束###################