laravel中报错:Syntax error or access violation: 1115 Unknown character set: 'utf8mb4'

原文:https://blog.csdn.net/snow_small/article/details/78802999

报错信息:

Illuminate \ Database \ QueryException (42000)
SQLSTATE[42000]: Syntax error or access violation: 1115 Unknown character set: 'utf8mb4'

报错原因:laravel5之后的mysql默认编码设置成了utf8mb4,低版本的mysql不能支持utf8mb4
可以查看自己的mysql版本,我的确实有点低了

[root@localhost app]# mysql -V
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

解决方法:
打开config/database.php修改:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => 'mr_',
'strict' => true,
'engine' => null,
],
为:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'mr_',
'strict' => true,
'engine' => null,
],
就是把charset以及collation改了,
问题解决!
————————————————
版权声明:本文为CSDN博主「snow_small」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/snow_small/java/article/details/78802999

posted @ 2020-06-08 15:08  鳳舞九天  阅读(555)  评论(0编辑  收藏  举报