首页  >  文章  >  数据库  >  Ubuntu更改MySQL字符集UTF-8,正确显示中文_MySQL

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

WBOY
WBOY原创
2016-06-01 13:11:13852浏览

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/ |+--------------------------+----------------------------+


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn