Windows下永久解決數據庫亂碼 utf8 轉 gbk


產生亂碼原因

因為windows終端的默認字符集是gbk編碼,而mysql數據庫是utf8的編碼,所以會產生亂碼問題

解決亂碼問題(臨時修改)

詢當前數據庫默認編碼:

mysql> show variables like 'character%';

修改為gbk編碼:

mysql> set names gbk;

但是這只是臨時修改,對新開啟的終端無效。

解決亂碼問題(永久)

修改MySQL的配置文件:my-default.ini

配置文件位於MySQL的安裝目錄

例如我的:C:\Program Files\MySQL\MySQL Server 5.7

[mysqld]character-set-server=gbk
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]character-set-server=gbk

# 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.
# basedir = .....
# datadir = .....
# port = .....
# 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 
my-default.ini

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM