在mysql中存儲中文時一般用UTF8的編碼方式,而用此編碼方式存儲emoji表情時,會出現亂碼或插入失敗,緣由是utf8編碼部支持emoji表情,至於爲何不支持,可參考這篇文章:mysql utf8mb4與emoji表情,所以須要將utf8編碼換成utf8mb4,步驟以下:php
ALTER TABLE `TABLE_NAME` MODIFY `COLUMN_NAME` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
config/databases.php
中設置mysql鏈接的編碼'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => 'FN_', 'strict' => false, 'engine' => null, ],
ok,如今就能在mysql中存儲emoji表情了mysql
原文地址:itisfun.xyzlaravel