《MYSQL數據庫MySQL插入中文不亂碼的5種方法》要點:
本文介紹了MYSQL數據庫MySQL插入中文不亂碼的5種方法,希望對您有用。如果有疑問,可以聯系我們。
方法一:
登錄MySQL,先做 set names latin1 ,然后在更新語句或者執行SQL語句MYSQL數據庫
mysql> set names latin1; mysql> source test.sql;
方法二:
在SQL文件中指定set names latin1;然后登錄MySQL,執行相應文件MYSQL數據庫
[root@localhost ~]# cat test.sql set names latin1; insert *****************; mysql> source test.sql;
方法三:
在SQL文件中指定set names latin1;然后通過MySQL命令導入MYSQL數據庫
[root@localhost ~]# mysql -uroot -p123456 test <test.sql
方法四:
通過指定MySQL命令的字符集參數實現--default-character-set=latin1MYSQL數據庫
[root@localhost ~]# cat test.sql insert *****************; [root@localhost ~]# mysql -uroot -p123456 --default-character-set=latin1 test <test.sql
方法五:推薦此方法,但是建議使用utf8
在配置文件里設置客戶端以及服務器端相關參數
即修改my.cnf 客戶端的模塊參數,可以實現set names utf8,且永久生效MYSQL數據庫
[client] default-character-set=utf8 無需重啟MySQL,退出當前登錄,重新登錄即可 [server] default-character-set=utf8 5.1以前的版本 character-set-server=utf8 5.5版本
庫表,程序!
MYSQL數據庫
mysql> show variables like 'character_set%'; | character_set_client | utf8 #客戶端字符集 | character_set_connection | utf8 #鏈接字符集 | character_set_database | utf8 #數據庫字符集,配置文件指定或者創建時指定 | character_set_results | utf8 #返回結果字符集 | character_set_server | utf8 #服務器字符集,配置文件,或者創建庫,表時候指定
本文出自 “crazy_sir” 博客MYSQL數據庫
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/1250.html