Linux, MySQL import excel file

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_42306122/article/details/96431196

First export excel file as a csv file utf-8 format (which does not need to excel header, only data on the line) ,

After (designated focus) and then use the notepad ++ open, select the "encoding" option "Use ANSI code" save uploaded to the server.

Usually installed MySQL encoding format is UTF-8, you can show variables like 'char%';see the following figure and if consistent, no need to set:
Here Insert Picture Description

Otherwise, please refer here to set the encoding (in full accordance with this article will not cause the file encoding and can not be imported, the difference in the above plans focus there)

Then create a database table → Create (be sure to set the primary key primary key):

create table shop_product (id int primary key auto_increment,
						   typename varchar(30),
					   	   name varchar(30),
						   price double(5,2), 
                           photos varchar(255));

If the error can not delete the table Times foreign key (foreign key) when you create a table error may refer to the following solutions:

This may be an association set up MySQL InnoDB foreign key in, the cause can not be updated or deleted data. This situation can be avoided by setting the variable FOREIGN_KEY_CHECKS.

SET FOREIGN_KEY_CHECKS = 0;

When removal is complete set

SET FOREIGN_KEY_CHECKS = 1;


Problems commonly encountered file permissions, given as follows:

"ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement"


At this time, can show variables like "secure_file_priv";be introduced to view the security file location mysql. Generally "/ var / lib / mysql- files /", the file can be copied to this directory


and import data

load data infile "/var/lib/mysql-files/3.csv" into table school_area character set utf8 fields terminated by "," lines terminated by '\r\n';

Guess you like

Origin blog.csdn.net/weixin_42306122/article/details/96431196