Home >Database >Mysql Tutorial >Ubuntu更改MySQL字符集UTF-8,正确显示中文_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:11:13873browse

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn