博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Encoding of mysql for mac
阅读量:7212 次
发布时间:2019-06-29

本文共 3123 字,大约阅读时间需要 10 分钟。

Chinese characters are not displayed properly in my terminal.

Solution: set all encoding in utf8

(in mysql using utf8 not utf-8)

Step1: check your encoding of mysql

mysql> show variables like "character%";+--------------------------+-----------------------+| 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/local/mysql-5.7.16-osx10.11-x86_64/share/charsets/ |+--------------------------+---------------------------+8 rows in set (0.00 sec)

Maybe your terminal would display diff from mine. That's OK and you have to set default encoding by modify the "my.cnf" file of mysql.

Step2 : Modify default encoding of mysql

 

Step3: Change the database & table encoding

mysql> alter database testDB character set utf8;Query OK, 1 row affected (0.01 sec)mysql> alter table testTB convert to character set utf8;Query OK, 0 rows affected (0.06 sec)Records: 0  Duplicates: 0  Warnings: 0

Check your database & table encoding now and remember to restart your mysql if necessary. 

 mysql> show create database testDB;

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

 | Database | Create Database   |

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

 | testDB   | CREATE DATABASE `testDB` /*!40100 DEFAULT CHARACTER SET utf8 */ |

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

 1 row in set (0.00 sec)

mysql> show create table testTB;+--------+----------------+| Table  | Create Table                                                                                              +--------+----------------+| testTB | CREATE TABLE `testTB` (  `testNum` varchar(16) NOT NULL,  `testName` varchar(32) NOT NULL,  `testDate` date NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+--------+----------------+1 row in set (0.01 sec)

Step4: change import file encoding

If you insert data by loading data infile, you have to makes sure the file has the same encdoing of utf8. The files I get from windows cannot directly use for importing. Mostly the files have Chinese character are encoding with gbk. You can open the file by Safari and click "view-encoding" to change into gbk. [cmd+A][cmd+c] copy the file into a new file opened by "text editor" and set preference of storing by encoding utf-8 in "open&store". Then the new file is totally can view in utf-8 with Chinese characters.

Finally you can import data form "test.txt" instead of insert data one by one.

mysql> load data local infile "/Users/.../Desktop/test.txt" into table testTB (testNum,testName,date);Query OK, 4 rows affected, 1 warning (0.00 sec)Records: 4  Deleted: 0  Skipped: 0  Warnings: 1

good luck!

 

转载于:https://www.cnblogs.com/22Kon/p/6713768.html

你可能感兴趣的文章
如何用消息系统避免分布式事务?
查看>>
Linux curl使用简单介绍 (转)
查看>>
Deep Learning(深度学习)学习笔记整理系列之(一)
查看>>
查看sqlserver被锁的表以及如何解锁
查看>>
WinCE的开发流程
查看>>
iOS网络层架构设计分享
查看>>
从 ReactiveCocoa 中能学到什么?不用此库也能学以致用
查看>>
linux上TCP connection timeout的原因查找
查看>>
DTMF的原理分析
查看>>
MODBUS-RTU通讯协议简介
查看>>
摄像机旋转约束问题及解决
查看>>
在.net中序列化读写xml方法的总结(转载)
查看>>
VC++ 使用CreateProcess创建新进程
查看>>
百度贴吧高考作文强贴
查看>>
管理 windows server 2003 的远程连接
查看>>
Apache+PHP 无法加载 MySql 模块的问题
查看>>
Leetcode: Design Hit Counter
查看>>
WPF中路由事件的传播
查看>>
ConfirmCancelUtilDialog【确认取消对话框封装类】
查看>>
FrameBuffer编程二(简单的程序上)
查看>>