1、找到my.cnf
[root@Sliver-Code ~]# vi /etc/my.cnf
加入下面三行语句
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
2、重启数据库
[root@Sliver-Code ~]# systemctl restart mariadb
3、验证是否修改
MariaDB [(none)]> SHOW VARIABLES LIKE '%colla%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
修改完成,再次插入的就时候,就不是问号了。
4、
insert into employee values(1,1001,'张三',26,'男','北京市海淀区');
insert into employee values(2,1002,'李四',24,'女','北京市昌平区');
insert into employee values(3,1003,'王五',25,'男','湖南省长沙市');
insert into employee values(4,1004,'Aric',15,'男','England');
MariaDB [demochar]> select * from employee;
+-----+------+--------+-----+-----+--------------------+
| num | d_id | name | age | sex | homeaddr |
+-----+------+--------+-----+-----+--------------------+
| 1 | 1001 | 张三 | 26 | 男 | 北京市海淀区 |
| 2 | 1002 | 李四 | 24 | 女 | 北京市昌平区 |
| 3 | 1003 | 王五 | 25 | 男 | 湖南省长沙市 |
| 4 | 1004 | Aric | 15 | 男 | England |
+-----+------+--------+-----+-----+--------------------+
需要注意的是,可能需要重新建表和库,因为我看到原来的表还是????.