Linux MariaDb 中文乱码

1.  修改/etc/mysql/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8 
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 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
[client] 
port=3306 
socket=/var/lib/mysql/mysql.sock 
default-character-set=utf8
[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


[mysql]

default-character-set=utf8

2.登录 MariaDB

MariaDB [(none)]> SHOW VARIABLES LIKE 'char%';

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | utf8                       |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | utf8                       |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

3.再输入以命令

SET character_set_client = utf8; 
SET character_set_results = utf8; 
SET character_set_connection = utf8;


4.重启 MariaDB

5.如果表是乱码之前建的表需要修改表字段的字符集;

Linux MariaDb 中文乱码_第1张图片


你可能感兴趣的:(Linux MariaDb 中文乱码)