MySQL、MariaDB修改默认字符集
修改2017.4.9:
最近在使用MariaDB,遇到了同樣的問題:中文亂碼。因為mariadb他有好幾個ini文件,但是可以根據自己開發需要創建一個my.ini,然后我試著去修改mariadb安裝目錄下的ini文件,死活不生效。然后我在C盤中搜索my.ini發現有一個。然后我就修改了,然后就可以啦
現在我自學到了SQL語句,發現在沒有選擇字符集時不能存入中文,然后今天看視屏,發現在自己的默認字符集是latin1,
這是什么鬼,然后自己上網查了,發現當初安裝沒設置就默認這個字符集,哦忘了我的MySQL是解壓版,原因是安裝版一直安裝不上
然后我就開始百度:怎么樣修改默認字符集,終于找到一篇博文,就是下面這篇,其中我提取了有用得精華,當然最下面我也會給出
那篇博文的URL;
首先你要查看自己的默認字符集:
查看語句是:show variables like 'character_set%';
然后修改語句是:SET character_set_server = utf8;?
SET character_set_database = utf8;
SET character_set_connection = utf8;我就不一一列出語句,就是后面要修改什么就寫什么;
這里只是單次修改,意思就是當你退出后再次進入還是會還原為原來的默認字符集latin1;
下面是設置永久的:
SET GLOBAL character_set_client = utf8; SET GLOBAL character_set_connection = utf8; SET GLOBAL character_set_database = utf8; SET GLOBAL character_set_results = utf8; SET GLOBAL character_set_server = utf8;
修改前:
修改后:
上面的方法是針對解壓版和安裝版;本人測試發現在我自己的電腦都不可以,最后我只能修改配置文件,其實修改配置文件并沒有那么可怕,開始我是不想去修改配置文件,但是實在沒辦法,才修改了,發現其實修改配置文件很簡單,而且一勞永逸,下面是我的配置文件,注意:我的是解壓版的MySQL,安裝版就別模仿了;
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/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. [mysql] default-character-set=utf8 [mysqld]# Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M# Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin# These are commonly set, remove the # and set as required. # basedir =D:\mysql-5.6.24-win32 # datadir =D:\mysql-5.6.24-win32\data # port =3306 # server_id = ..... character-set-server = utf8# Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES注意:
# basedir =D:\mysql-5.6.24-win32 # datadir =D:\mysql-5.6.24-win32\data 這兩處是你們自己MySQL安裝的路徑,改成自己的;
我覺得數據庫還是要選擇utf8,因為方便將來遷移,而且不容易亂碼吧,但是utf8也有個缺點,就是不能按中文拼音排序,就是校對規則比較麻煩,好了學習去了,時間很緊迫,切莫再任命的時候任性,要不會很慘。。。
這是我看到的那篇關于默認字符集的博文,對我有幫助的呢:http://imysql.cn/taxonomy/term/24
總結
以上是生活随笔為你收集整理的MySQL、MariaDB修改默认字符集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 推荐一篇关于java集合的博文,写的很n
- 下一篇: java super和this总结