欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ubuntu下mysql修改字符集latin1为utf-8

程序员文章站 2023-09-19 21:53:32
查看数据库字符集状态: show VARIABLES like '%char%' 查看结果: character_set_client utf8 c...

查看数据库字符集状态:

show VARIABLES like '%char%'

查看结果:

character_set_client	utf8
character_set_connection	utf8
character_set_database	utf8
character_set_filesystem	binary
character_set_results	utf8
character_set_server	latin1
character_set_system	utf8
character_sets_dir	/usr/share/mysql/charsets/

上面的字符集有一个是latin1,要修改为utf-8.

解决方式:

到服务器/etc/mysql/mysql.conf.d找到mysqld.cnf

在[mysqld] 下新增

character_set_server=utf8 #增加这一行,指定字符集

重启数据库:

sudo service mysql restart

再次查看字符集:

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/