Mysql匯入大容量SQL檔案資料問題

來源:互聯網
上載者:User

標籤:

MySQL在通過匯入sql檔案可能會出現下面二個問題:

1.如果sql檔案過大,會出現"MySQL server has gone away"問題;

2.如果sql檔案資料有中文,會出現亂碼

 

解決問題:

問題1:出現MySQL server has gone away"問題,是因為mysql預設的"max_allowed_packet"變數值過小.

查看目前配置

show VARIABLES like ‘%max_allowed_packet%‘;

顯示的結果為:

 

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

| Variable_name      | Value   |

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

| max_allowed_packet | 1048576 |

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

說明目前的配置是:1048576/1024/1024 = 1M

 

修改max_allowed_packet值:

方法1: SET GLOBAL max_allowed_packet = 500*1024*1024;(經測試無效)

方法2: 直接修改設定檔,重啟mysql

             windows中修改my.ini檔案,在linux中修改my.cnf檔案.

             C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\my.ini(安裝mysql時的,指定的資料檔案目錄)

             

            重啟mysql後,在查看修改後的max_allowed_packet值

             

 

問題2:登入時指定字元集編碼

            mysql -uroot -P3308 -p123456  - -default-character-set=utf8  (-P是指指定連接埠號碼)

            

           

 

最後通過source命令 即可成功匯入:

              source  E:ydj\test.sql

             

Mysql匯入大容量SQL檔案資料問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.