Mysql 5.7.26
1、编辑配置文件
sudo vim /etc/mysql/mysql.conf.d/f
加入下面标红加粗部分。
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
2、重启服务
sudo service mysqld restart
3、检查变量
mysql -uroot -p******mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
+--------------------------+----------------------------+
| Variable_name| Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4|
| character_set_connection | utf8mb4|
| character_set_database | utf8mb4|
| character_set_filesystem | binary |
| character_set_results | utf8mb4|
| character_set_server | utf8mb4|
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8mb4_unicode_ci|
| collation_database | utf8mb4_unicode_ci|
| collation_server| utf8mb4_unicode_ci|
+--------------------------+----------------------------+
加粗部分若如上显示,则配置成功
3、创建数据库
mysql> create user laravelshop IDENTIFIED by '123456';mysql> CREATE DATABASE IF NOT EXISTS laravelshop DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;mysql> GRANT ALL PRIVILEGES ON laravelshop.* TO laravelshop@"%" IDENTIFIED BY '123456';mysql> flush privileges;
如果觉得《mysql 存储表情符号》对你有帮助,请点赞、收藏,并留下你的观点哦!