I create a table in mysql on macos commandline using the 'utf-8' charset,
mysql>  CREATE TABLE tb_stu (id VARCHAR(20), name VARCHAR(20), sex CHAR(1), birthday DATE) default charset=utf8;
Query OK, 0 rows affected (0.02 sec)
mysql> SHOW TABLES;
+----------------+
| Tables_in_test |
+----------------+
| pet            |
| tb_stu         |
+----------------+
2 rows in set (0.00 sec)
mysql> show create table tb_stu \G
*************************** 1. row ***************************
       Table: tb_stu
Create Table: CREATE TABLE `tb_stu` (
  `id` varchar(20) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  `sex` char(1) DEFAULT NULL,
  `birthday` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
I want to add some values to the 'tb_stu' table, I have a txt file containing Chinese string :
1   小明  男   2015-11-02
2   小红  女   2015-09-01
3   张三  男   2010-02-12
4   李四  女   2009-09-10
and the txt file is 'utf-8' charset too!
➜  ~ file /Users/lee/Desktop/JAVA/Java从入门到精通/第18章--使用JDBC操作数据库/Example_18_02/tb_stu.txt
/Users/lee/Desktop/JAVA/Java从入门到精通/第18章--使用JDBC操作数据库/Example_18_02/tb_stu.txt: UTF-8 Unicode text
so I execute the mysql command line:
mysql> LOAD DATA LOCAL INFILE '/Users/lee/Desktop/JAVA/Java从入门到精通/第18章--使用JDBC操作数据库/Example_18_02/tb_stu.txt' INTO TABLE tb_stu;
Query OK, 4 rows affected, 4 warnings (0.01 sec)
Records: 4  Deleted: 0  Skipped: 0  Warnings: 4
but I get the messy code in mysql :
mysql> select * from tb_stu;
+------+----------------+------+------------+
| id   | name           | sex  | birthday   |
+------+----------------+------+------------+
| 1    | å°æ˜Ž         | ç    | 2015-11-02 |
| 2    | å°çº¢         | å    | 2015-09-01 |
| 3    | 张三         | ç    | 2010-02-12 |
| 4    | æŽå››         | å    | 2009-09-10 |
+------+----------------+------+------------+
4 rows in set (0.00 sec)
it makes me confused, the tabel in mysql and the txt are both 'utf-8' charset, why I get the messy code? thanks a lot!
 
    