1. 修改/etc/mysql/my.cnfmysql
[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]sql
default-character-set=utf8shell
2.登陸 MariaDBsocket
MariaDB [(none)]> SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------+spa
| Variable_name | Value |code
+--------------------------+----------------------------+server
| character_set_client | utf8 |it
| character_set_connection | utf8 |io
| character_set_database | utf8 |event
| 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.若是表是亂碼以前建的表須要修改表字段的字符集;