mysql 修改默认编码_MySQL修改默认编码

首先进入MySQL查看当前默认编码:

mysql> SHOW VARIABLES LIKE 'character%';

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

| Variable_name | Value |

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

| character_set_client | latin1 |

| character_set_connection | latin1 |

| character_set_database | latin1 |

| character_set_filesystem | binary |

| character_set_results | latin1 |

| character_set_server | latin1 |

| character_set_system | utf8 |

| character_sets_dir | /rdsdbbin/oscar-5.6.10a.16.21/share/charsets/ |

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

8 rows in set (0.02 sec)

能够看到大部分都是latin1,现在想把默认编码改成uft8

可以直接执行set命令:

SET character_set_client = utf8;

SET character_set_connection = utf8;

SET character_set_database = utf8;

SET character_set_results = utf8;

SET character_set_server = utf8;

然后 mysql> SHOW VARIABLES LIKE 'character%'; 可以看到全变为utf8

但是,这只是一种假象。此种方式只在当前状态下有效,当重启数据库服务后失效。

所以想要不出现乱码只有修改MySQL配置文件my.cnf(windows下my.ini)。

找到配置文件(Linux下一般是/etc/my.cnf)

打开文件,标签下没有的要添加,有的就修改:

[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

default-character-set=utf8

重新连接数据库,再做查询:

mysql> SHOW VARIABLES LIKE 'character%';

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

| Variable_name | Value |

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

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | latin1 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | latin1 |

| character_set_system | utf8 |

| character_sets_dir | /rdsdbbin/oscar-5.6.10a.16.21/share/charsets/ |

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值