程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql 從文件導入sql 亂碼問題...

mysql 從文件導入sql 亂碼問題...

編輯:MySQL綜合教程

 

首先我拿到sql文件沒亂碼,(用ultraedit 管理員界面可以看到文件編碼)

 

數據庫編碼和文件一致

 

下面就進到mysql裡面看看variables

www.2cto.com

mysql> show variables like "%char%"; 

+--------------------------+---------------------------------------------------------------------------------+ 

| Variable_name            | Value                                                                           | 

+--------------------------+---------------------------------------------------------------------------------+ 

| character_set_client     | latin1                                                                          | 

| character_set_connection | latin1                                                                          | 

| character_set_database   | utf8                                                                            | 

| character_set_filesystem | binary                                                                          | 

| character_set_results    | latin1                                                                          | 

| character_set_server     | utf8                                                                            | 

| character_set_system     | utf8                                                                            | 

| character_sets_dir       | /usr/local/Percona-Server-5.1.57-rel12.8-233-Linux-x86_64/share/mysql/charsets/ | 

+--------------------------+---------------------------------------------------------------------------------+ 

8 rows in set (0.01 sec) 

www.2cto.com

mysql> show variables like "%coll%"; 

+----------------------+-------------------+ 

| Variable_name        | Value             | 

+----------------------+-------------------+ 

| collation_connection | latin1_swedish_ci | 

| collation_database   | utf8_bin          | 

| collation_server     | utf8_bin          | 

+----------------------+-------------------+ 

3 rows in set (0.00 sec) 

 

 

有幾個latin1的...

 

原來是connection的變量是latin1... 忍不了

 

 

修改sql文件

 

SET collation_connection = utf8_bin;

 

SET character_set_client = utf8;

 

SET character_set_connection = utf8;

 

 

mysql  --socket=/opt/mydata/my3306/my3306.sock -A < xxx.sql 就好了...

 

摘自 sunvince的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved