Posts Tagged ‘ssh’
Bulk load data in SharedHosting mySQL
January 7, 2021
Leave a comment
Process to bulk import csv file in mysql database on shared shoting –
1) Upload the csv file on server using FTP for FileManager
2) Connect to SSH
3) run this linux command to create a function (refer – https://stackoverflow.com/questions/5265702/how-to-get-full-path-of-a-file/52200174#52200174)
This command will provide you complete path of the uploaded file.
abspath() { old=pwd;new=$(dirname "$1");if [ "$new" != "." ]; then cd $new; fi;file=pwd/$(basename "$1");cd $old;echo $file; }
abspath <filename>
4) Once you get the complete path of the file use login to mysql using
mysql -u <username> -p --local-infile
5) Run below command to load the data of the file to a specific table with column specified
LOAD DATA LOCAL INFILE '<filename>'
INTO TABLE <tablename>
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(column1,column2,column3);