sql General error: 1267 Illegal mix of collations (utf8mb4_general_ci,IMPLICIT)

@yangweijie 2018-06-21 08:55:39发表于 yangweijie/note blogenhancementmysqlshellsql

今天客户的微信注册遇到昵称问题

image

开始找了个修改表结构的sql 改了几个特殊字段, 结果还是报错

索性tp写了个循环后 将所有表的字符全改utf8mb4了

  public function modify_table_charset(){
   	$tables = Db::query('show tables');
   	$sql = '';
   	foreach ($tables as $t) {
   		$sql .= PHP_EOL.<<<SQL
ALTER TABLE {$t['Tables_in_novel']} CONVERT TO CHARACTER SET utf8mb4 collate utf8mb4_general_ci;

SQL;

   	}
   	echo $sql;
   }

还有改数据库默认编码