使mysql数据库支持简体中文

永久支持简体中文
[root@localhost ~]# vim /etc/my.cnf
添加如下四行:
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

 

若想数据库database支持中文,如下:

修改/etc/my.cnf

[client]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d

[root@localhost ~]# systemctl restart mariadb

MariaDB [auth]> show variables like 'character_set_%';    //查看字符集是否支持中文

临时支持简体中文
[root@localhost ~]# mysql -uroot -p123123
MariaDB [(none)]> charset utf8;
Charset changed

你可能感兴趣的