mysql中文乱码解决
今天迁移博客,然后一堆问题,日了狗了,最糟心的就是MySQL中文乱码的问题了
网上的资料一堆坑,各种全角字符,改起来特别闹心,我这个可以无脑复制
然后开始内容
系统centos6.8
MySQL使用
yum install mysql-server
首先安装完配置一下
/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
collation-server = utf8_unicode_ci
init-connect= 'SET NAMES utf8'
character-set-server = utf8
character-set-filesystem = utf8
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
新建数据表请使用
CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
启动后检查配置
SHOW VARIABLES LIKE 'character%';
mysql> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
提示如下就不会出现乱码了