Ubuntu下設定MySQL字元集為utf8

來源:互聯網
上載者:User

Ubuntu下設定MySQL字元集為utf8

Ubuntu下設定MySQL字元集為utf8

1.mysql設定檔地址
/etc/mysql/my.cnf

2.在[mysqld]在下方添加以下代碼
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

3.重啟mysql服務
sudo service mysql restart

4.檢測字元集是否更新成utf8.
進入mysql,mysql -u root -p,輸入show variables like '%character%' 查看字元集
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

注意事項:在修改字元集之前已經建立的資料庫,character_set_database值不會發生改變,往資料庫中插入中文資料仍然會顯示亂碼,所以最好在安裝完MySQL後就將字元集改成utf8,否則後續修改會較麻煩。

相關文章

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.