Reasons for character error in MySQL command line interface and solutions
- 2020-12-19 21:14:47
- OfStack
ERROR 2019 (HY000): Can't initialize character set gb2312
It took a long time for MySQL to be reinstalled twice.
I've set the system code to be es5EN-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
The database is also 1 directly configured with 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
I don't know how to come up with gb2312
After searching for a long time, I finally found that it should be the content coding problem of the terminal input. I remembered that I had changed it to make SSH display Chinese normally
vi /etc/profile
LANG=zh_CN.GB2312
export LANG
This is the reason for the change, so I comment it out and then I close ssh and I relink it and it works,
PS: MySQL import garbled code solution
Garbled code occurs when importing, and the encoding format of specified imported data needs to be added in the statement:
mysql -uroot -p database_name < database_backup.sql --default-character-set=utf8