Q: How can I import a csv file to a MySQL database (the csv file contains Chinese content )?
The contents of the CSV file are as follows:
The table structure is as follows:
Bytes ----------------------------------------------------------------------------------------------
The procedure is as follows:
1. Modify the table and field encoding method to support Chinese Characters
The table name is [demo]. The fields to be modified include username and password.
1 alter table demo character set gb2312;
2 alter table demo MODIFY username varchar (20) character set gb2312; 3 alter table demo MODIFY password varchar (20) character set gb2312;
2. view the encoding Modification result
Show create table demo;
3. Import the csv file. The file name and path are D:/insert_data.csv.
1 load data infile "d:/insert_data.csv"
2 REPLACE INTO TABLE DEMO
3 character set gb2312
4 fields terminated by "," enclosed ""
5 lines terminated by "\ r \ n ";
4. Check the import effect after the execution is successful.