方法一:
登錄mysql,先做 set names latin1 ,然后在更新語(yǔ)句或者執(zhí)行SQL語(yǔ)句
mysql> set names latin1; mysql> source test.sql;
方法二:
在SQL文件中指定set names latin1;然后登錄MySQL,執(zhí)行相應(yīng)文件
[root@localhost ~]# cat test.sql set names latin1; insert *****************; mysql> source test.sql;
方法三:
在SQL文件中指定set names latin1;然后通過(guò)MySQL命令導(dǎo)入
[root@localhost ~]# mysql -uroot -p123456 test <test.sql><p><strong>方法四:<br></strong>通過(guò)指定MySQL命令的字符集參數(shù)實(shí)現(xiàn)--default-character-set=latin1</p> <p> </p> <pre class="prebrush"> [root@localhost ~]# cat test.sql insert *****************; [root@localhost ~]# mysql -uroot -p123456 --default-character-set=latin1 test <test.sql><p><strong>方法五:推薦此方法,但是建議使用utf8</strong><br> 在配置文件里設(shè)置客戶(hù)端以及服務(wù)器端相關(guān)參數(shù)<br> 即修改my.cnf 客戶(hù)端的模塊參數(shù),可以實(shí)現(xiàn)set names utf8,且永久生效</p> <p> </p> <pre class="brush:plain;"> [client] default-character-set=utf8 無(wú)需重啟MySQL,退出當(dāng)前登錄,重新登錄即可 [server] default-character-set=utf8 5.1以前的版本 character-set-server=utf8 5.5版本
庫(kù)表,程序!
代碼如下:
CREATE DATABASE wyb? DEFAULT CHARACTER SET utf8 collate utf8_general_cli;
字符集含義總結(jié)表
mysql> show variables like 'character_set%'; | character_set_client | utf8 #客戶(hù)端字符集 | character_set_connection | utf8 #鏈接字符集 | character_set_database | utf8 #數(shù)據(jù)庫(kù)字符集,配置文件指定或者創(chuàng)建時(shí)指定 | character_set_results | utf8 #返回結(jié)果字符集 | character_set_server | utf8 #服務(wù)器字符集,配置文件,或者創(chuàng)建庫(kù),表時(shí)候指定
本文出自 “crazy_sir” 博客
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END