Linux下設定Mysql資料庫編碼

來源:互聯網
上載者:User

標籤:

重裝系統後,要裝個mysql伺服器,發現添加資料時,一直錯誤,查其原因,原來時編碼問題。Google了一下,可都不太一樣,可能時資料庫版本問題吧。

查看資料庫版本:

select version();

 

顯示:‘5.7.15-0ubuntu0.16.04.1‘

官方文檔:Mysql Document

1、查看資料庫編碼

show variables like ‘character%‘;

 

顯示結果:

character_set_client

utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
character_set_client為用戶端編碼方式;character_set_connection為建立串連使用的編碼;character_set_database資料庫的編碼;character_set_results結果集的編碼;character_set_server資料庫伺服器的編碼;

只要保證以上四個採用的編碼方式一樣,就不會出現亂碼問題。

2、設定資料庫編碼

 分為兩部分:設定資料庫伺服器編碼和設定資料庫編碼

設定資料庫編碼比較簡單,在建立資料庫時,可以指定編碼;

設定伺服器編碼的話,需要修改設定檔。設定檔路徑為:/etc/mysql/mysql.conf.d

找到[mysqld],在後面添加如下代碼後,重啟伺服器即可。

character-set-server=utf8collation-server=utf8_general_ci

 

 

3、重啟資料庫

service mysql restart

 

Linux下設定Mysql資料庫編碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.