Encoding of mysql for mac

來源:互聯網
上載者:User

標籤:charset   date   cannot   safari   pre   import   convert   result   edit   

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

http://www.cnblogs.com/jinjidedale/p/6183451.html 

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!

 

Encoding of mysql for mac

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.