windows修改mysql字符集_Windows下修改MySql默認字符集

做開發時很多時候會碰到亂碼的問題;

有的時候可能是從后台傳到數據庫時亂碼,這時候可能就是數據庫默認的字符集編碼有問題

默認的字符集為

mysql配置文件為my.ini(在linux下為my.cnf)

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# 設置mysql的安裝目錄

basedir = D:/soft/mysql-5.6.36-winx64

# 設置mysql數據庫的數據的存放目錄,必須是data

datadir = D:/soft/mysql-5.6.36-winx64/data

port =3306

# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

在doc下進入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 | latin1 |

| character_sets_dir | /usr/share/mysql/charsets/ |

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

解決方案:

修改配置文件

mysql配置文件為my.ini(在linux下為my.cnf)

找到[mysqld] 添加:

character-set-server=utf8

init_connect='SET NAMES utf8'

然后在最后面添加

[client]

default-character-set=utf8

修改后為:

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# 設置mysql的安裝目錄

basedir = D:/soft/mysql-5.6.36-winx64

# 設置mysql數據庫的數據的存放目錄,必須是data

datadir = D:/soft/mysql-5.6.36-winx64/data

port =3306

character-set-server=utf8

init_connect='SET NAMES utf8'

# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]

default-character-set=utf8

重啟mysql服務

然后在查看mysql編碼

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

| Variable_name | Value |

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

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

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

搞定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值