Excel file to mysql - mysql

I am creating a web application to collect some specific data from users. What I want is that the user uploads an excel file containing the data on the web page I created and that excel file stores its data on MySQL database.
Is it possible?How?

It's possible.
I would convert the Excel file to a csv file, or make the user upload a csv file instead. Excel already has this feature build in.
Then in MySQL you can turn the csv file into a tmp table with ease:
LOAD DATA LOW_PRIORITY LOCAL INFILE 'C:\\Users\\Desktop\\nameoffile.csv' REPLACE INTO TABLE `tmp_table` CHARACTER SET latin1 FIELDS TERMINATED BY ';' LINES TERMINATED BY '\r\n';
After that you transfer your data from the tmp table into the tables you'd like and finally you delete the temporary table.

Related

how to create a mysql table by csv file header?

My goal is to create a MySQL table containing data from my CSV file.
is there any way to do this
i don't know whether it is possible or not thorugh csv. the thing is like i want to generate mysql table using csv headers as filed names i know how to load csv into table which is already created manually but i want to generate table through csv using batch script and below is my batch script to load csv into table through manually
load data local infile "C:\\EQA\\project\\input1.csv"
into table request_table
character set latin1
fields terminated by','
ENCLOSED BY '"'
lines terminated by'\r\n'
IGNORE 1 ROWS
here above code is for to load csv into table in which request_table is existing in db.
but i want to load csv into table dynamically?
is that possible?if so can some one help me out to accomplish this?

Import Excel sheet data in to Mysql using Web application

I need to upload data in an excel sheet to the database using java.
The database will be oracle.
The excel sheet will be uploaded once in a month by a user using a web application (Servlets and JSP).
The excel sheet will be having thousands of records/rows e.g. around 15000 or more.
What is the fastest way to upload this huge data in database? We are using simple JDBC (Spring's JDBC Template).
How do we handle transaction sand errors as there can be errors while uploading data in which case the partly uploaded data will be useless?
We need to able to notify the user of the error so that he can correct the excel sheet and try again?
Please help/
To import excel sheet data into mysql, first convert it to csv and then use following code to import it in database
Login to mysql
mysql -u root -p
<type password>
Import data to table using this query
LOAD DATA INFILE 'data.csv' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
here the data.csv file must be located at valid path specified by mysql default configuration, typically you have to save this data.csv at /var/tmp/ path. If you wish to specify custom path where file is located e.g. /home/ubuntu/data.csv then make sure that secure-file-priv is disabled.

How do I update CSV file into mysql Database?

Hello I wondering is there way I can update a CSV file into mysql database. At this current time I have created a database in mysqlworkbench which connected to mysql sever. Then I upload CSV file into database which updates auto on webmin webserver.
The question I want to ask is how can I link new CSV file onto the database automatically.
Create database table with same numbers of columns present in the csv file.
Run following query:
LOAD DATA INFILE 'c:/import.csv' INTO TABLE <table> FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n'

How to bulk insert text files into MySQL table?

I just wanted to ask your expertise in bulk insert into mysql table, as of now this script is working fine:
LOAD DATA INFILE 'C:\\test\\cdr_june1.txt' INTO TABLE bod FIELDS TERMINATED BY ',';
But this past few days my text file have different file name, I was thinking to load all the file with .txt extension. How can I do this?

Replace contents of MySQL table with contents of csv file on a remote server

I'm a newbie here trying to import some data into my wordpress database (MySQL) and I wonder if any of you SQL experts out there can help?
Database type: MySQL
Table name: wp_loans
I would like to completely replace the data in table wp_loans with the contents of file xyz.csv located on a remote server, for example https://www.mystagingserver.com/xyz.csv
All existing data in the table should be replaced with the contents of the CSV file.
The 1st row of the CSV file is the table headings so can be ignored.
I'd also like to automate the script to run daily at say 01:00 in the morning if possible.
UPDATE
Here is the SQL I'm using to try and replace the table contents:
LOAD DATA INFILE 'https://www.mystagingserver.com/xyz.csv'
REPLACE
INTO TABLE wp_loans
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
IGNORE 1 LINES
I would recommend a cron job to automate the process, and probably use BCP (bulk copy) to insert the data into a table... But seeing as you are using MySQL, instead of BCP, try load data in file - https://mariadb.com/kb/en/load-data-infile/