Home >Database >Mysql Tutorial >MySQL命令行界面中出现字符错误提示的原因及解决方法_MySQL

MySQL命令行界面中出现字符错误提示的原因及解决方法_MySQL

WBOY
WBOYOriginal
2016-05-27 10:44:191472browse

ERROR 2019 (HY000): Can't initialize character set gb2312
搞了好半天,MySQL都重装了两次,号悲剧。。。
之前设置了系统编码全都是UTF-8了的

vi /etc/sysconfig/i18n 

 

LANG=zh_CN.UTF-8 
LANGUAGE=zh_CN.UTF-8:zh_CN.GB2312:zh_CN 
SUPPORTED=zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en 
SYSFONT=lat0-sun16 

数据库也一直配置的 utf8

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ 
-DDEFAULT_CHARSET=utf8 \ 
-DDEFAULT_COLLATION=utf8_general_ci \ 
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ 
-DWITH_MYISAM_STORAGE_ENGINE=1 \ 
-DENABLED_LOCAL_INFILE=ON \ 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 
-DWITH_READLINE=1 \ 
-DENABLED_LOCAL_INFILE=1 \ 
-DMYSQL_DATADIR=/var/mysql/data 

不知道怎么冒出个 gb2312 来
找了好久最后终于发现应该是终端输入内容编码的问题,想起之前为了让 SSH 正常显示中文修改了

vi /etc/profile  

LANG=zh_CN.GB2312 
export LANG 


这地方给修改过的原因,于是将它注释掉然后关了 ssh 重新链接后执行命令就正常了,

PS:MySQL导入乱码解决
导入时出现乱码,需要在语句中添加指定导入数据的编码格式:

mysql -uroot -p database_name < database_backup.sql --default-character-set=utf8

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn