如何将mysql默认编码改为UTF8
将mysql默认编码改为UTF8的方法:
windows:
a. WIN+Rnet stop mysql关闭mysql服务
b. 复制my-dafault.ini,重命名为my.ini,进入里面
UBUNTU:** sudo vim /etc/mysql/my.cnf **进入执行以下操作:
1、在[client]字段里加入default-character-set=utf8,如下:[client]port = 3306socket = /var/lib/mysql/mysql.sockdefault-character-set=utf82、在[mysqld]字段里加入character-set-server=utf8,如下:[mysqld]port = 3306socket = /var/lib/mysql/mysql.sockcharacter-set-server=utf83、在[mysql]字段里加入default-character-set=utf8,如下:[mysql]no-auto-rehashdefault-character-set=utf8修改完成后,service mysql restart重启mysql服务就生效。注意:[mysqld]字段与[mysql]字段是有区别的。这点在网上没人反馈过。
注: show variables like 'character%' 可查看mysql编码方式,修改完成后是这样的:+--------------------------+----------------------------+| 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/ |+--------------------------+----------------------------+以上就是如何将mysql默认编码改为UTF8的详细内容,更多请关注小潘博客其它相关文章!