登录数据库后,选择数据库然后执行
MariaDB [test]> status;
--------------
mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
Connection id: 6
Current database: test
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 5.5.68-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8 ## 确保这个是 utf8 ##
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 8 hours 12 min 11 sec
Threads: 1 Questions: 87 Slow queries: 0 Opens: 5 Flush tables: 2 Open tables: 29 Queries per second avg: 0.002
--------------
MariaDB [test]>
确保 Db characterset
的值是 utf8
如果不是,则修改 /etc/my.cnf
配置文件
[mysqld]
# 新增如下2行
character-set-server=utf8
collation-server=utf8_general_ci
创建数据库和数据表并指定字符集
创建数据库
CREATE DATABASE dbname CHARACTER SET utf8;
创建表
CREATE TABLE tablename (id int,name text) default charset=utf8;