当前位置:Gxlcms > mysql > Ubuntu更改MySQL字符集UTF-8,正确显示中文_MySQL

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

时间:2021-07-01 10:21:17 帮助过:15人阅读

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

人气教程排行