摘要:Ubuntu Server 服务器下使用apt-get 命令安装的mysql,默认不是utf8、在这里记录一下如何将编码修改成utf8。
办法解决:
1.查看mysql编码
show variables like ‘%character%‘;
+--------------------------+----------------------------+ | 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/ | +--------------------------+----------------------------+
默认情况下使用apt-get 下载安装的mysql编码 并非utf8,这在开发中非常的蛋疼!!
2.修改mysql的配置文件——/etc/mysql/my.cnf:
a) 打开mysql配置文件:
vim/etc/mysql/my.cnf
b) 在[client]下追加:
default-character-set=utf8
c) 在[mysqld]下追加:
character-set-server=utf8
d) 在[mysql]下追加:
default-character-set=utf8
e) 保存并退出
3 重启mysql服务
service mysql restart
4 查看mysql编码是否修改成功
a.登录MySQL
mysql -u username -p
b.查看编码
show variables like ‘%character%‘;
时间: 2024-10-24 21:02:49