首頁 > 資料庫 > mysql教程 > Ubuntu更改MySQL字符集UTF-8,正确显示中文_MySQL

Ubuntu更改MySQL字符集UTF-8,正确显示中文_MySQL

WBOY
發布: 2016-06-01 13:11:13
原創
875 人瀏覽過

Ubuntu

首先停mysql服务,编辑配置文件my.cnf

$ sudo stop mysql$sudo vim /etc/mysql/my.cnf
登入後複製

[client] default-character-set=utf8 #增加这一行,指定字符集port            = 3306 socket          = /var/run/mysqld/mysqld.sock .............[mysqld] character_set_server=utf8 #增加这一行,指定字符集user            = mysql pid-file        = /var/run/mysqld/mysqld.pid
登入後複製

重启服务,字符集就成了UTF-8

$ sudo start mysql$ sudo mysql -uroot -pmysql> use rootmysql> show variables like '%char%' ;#更改前存在的用户字符集不会改变,以后新建的用户字符集都变成了UTF-8+--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | utf8                       || character_set_connection | utf8                       || character_set_database   | latin1                     || character_set_filesystem | binary                     || character_set_results    | utf8                       || character_set_server     | utf8                       || character_set_system     | utf8                       || character_sets_dir       | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+mysql> create database mydb;mysql> use mydbmysql> show variables like '%char%';+--------------------------+----------------------------+| 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/ |+--------------------------+----------------------------+
登入後複製


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板