查看字符编码
1 show variables like "%char%"
字符编码
mysql> show variables like "%char%"; +--------------------------+--------------------------------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------------------------------+ | character_set_client | utf8 客户端字符编码 | | character_set_connection | utf8 连接使用字符编码 | | character_set_database | latin1 数据库使用字符编码 | | character_set_filesystem | binary 系统默认使用格式 | | character_set_results | utf8 | | character_set_server | latin1 服务端字符编码 | | character_set_system | utf8 系统使用字符编码 | | character_sets_dir | /usr/src/mysql-5.7.22-linux-glibc2.12-x86_64/share/charsets/ | +--------------------------+--------------------------------------------------------------+ 8 rows in set (0.00 sec)
修改字符编码
临时修改 set character_set_server=utf8 永久修改 vim /etc/my.conf cat /etc/my.conf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character_set_server=utf8 添加的数据 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
查看表使用的字符编码格式
show create table 表名
修改表使用的字符编码格式
alter table name default character set latin 1
常见字符编码
ASCLL 英文 GB2312 中文 GBK 中文 UTF-8 万国字符集 UTF-16 万国字符集