TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
1, 用 SHOW VARIABLES LIKE 'character_set_%'; 查看一下 显示
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8|
| character_set_connection | utf8|
| character_set_database | latin1 |
| character_set_results | utf8|
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /home/jh/mysql/share/mysql/charsets |
+--------------------------+----------------------------+
再用 SHOW VARIABLES LIKE 'collation_%'; 查看一下 显示
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | utf8_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
原来如此啊 哈哈 知道错在哪里 剩下的就好办了
解决方法:
依次执行:
set character_set_database =utf8;
set character_set_results =utf8;
set character_set_server =utf8;
set character_set_system =utf8; --此处utf-8也可以
然后执行:
SET collation_server = utf8_chinese_ci
SET collation_database = utf8_chinese_ci
执行完之后,请检查mysql下每个数据库,表,字段是否都是utf8,不是则改过来,这样子就不会出现
最终解决方法:
1.1 如果是windows版本的mysql,那么在安装的时候,系统就会提示用哪种编码。
如果安装的时候设置错误了,修改mysql安装目录下的my.ini文件:
[mysql]
default-character-set=utf8
...
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
配置好后,重启mysql。
1.2 如果是linux版本的mysql
修改mysql的配置文件,使数据库与服务器操作系统的字符集设置一致。
vi /etc/my.cnf 设置(如果没有发现这个文件,就新建1个)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8 (增加的关键一句,使得数据库缺省以utf8存储)
当然,修改后,要重启数据库。(这样设置后对新建的数据库表才起作用) |
|