查看Mysql的编码和库、表里的是否一致
show variables where Variable_name like 'collation%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
里面的collation没有不一致,而mysql5.5默认的collation为utf8_general_ci,
查看服务器的my.cnf文件有配置 windows下面是my.ini文件
如果忘记了MySQL的安装目录,可以进入mysql输入命令快速找到
show variables like "%char%";
mysql> 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 | D:\mysql-5.6.31-winx64\share\charsets\ |
+--------------------------+----------------------------------------+
8 rows in set (0.00 sec)
mysql>
可能是存储过程执行中创建临时表时collation用的是utf8_general_ci,造成创建临时表和实际的两张表字段collation不匹配才报的这个错误,那么要真是这样的话,就得配置my.ini让Mysql和我们的表的collation一样,就可以了。
于是在my.ini文件中修改成这样:
[client]
port=3306
default-character-set=utf8
[mysqld]
port=3306
character_set_server=utf8
collation_server=utf8_general_ci
重启Mysql,再把存储过程中的两张表和字段全部使用utf8_general_ci,然后把数据库也设置成utf8_general_ci,再执行存储过程,OK!可以运行了