设置步骤: 一、编辑MySql的配置文件 MySql的配置文件Windows下一般在系统目录下或者在MySql的安装目录下名字叫my-default.ini,可以搜索,Linux下一般是 / etc /my.cnf default-character-set = utf8 character_set_server = utf8 lower_case_table_names =
设置步骤:
一、编辑MySql的配置文件
MySql的配置文件Windows下一般在系统目录下或者在MySql的安装目录下名字叫my-default.ini,可以搜索,Linux下一般是 /etc/my.cnf
default-character-set = utf8
character_set_server = utf8
lower_case_table_names = 1 //表名不区分大小写(此与编码无关)
default-character-set = utf8
default-character-set = utf8
default-character-set = utf8
default-character-set = utf8
二、重新启动MySql服务
Windows可在服务管理器中操作,也可使用命令行:
net stop mysql 回车
net start mysql 回车
服务名可能不一定为mysql,请按自己的设置
Linux下面可是用 service mysql restart
如果出现启动失败,请检查配置文件有没有设置错误
?
?
三、查看设置结果
登录MySql命令行客户端:打开命令行
mysql –uroot –p 回车
输入密码
进入mysql后 执行 :show variables like "%char%";
显示结果应该类似如下:
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
如果仍有编码不是utf8请用mysql命令设置:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
以上命令有部分只对当前登录有效,所以不是很管用。