Created
October 25, 2017 03:57
-
-
Save bosukh/3695949aa68754026451df98fa2d4b5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -ne 5 ]; then | |
echo "Need the following arguments: filename, table_name, db_name, username, password" | |
exit 1 | |
fi | |
csv_filename=$1 | |
table_name=$2 | |
db_name=$3 | |
username=$4 | |
password=$5 | |
mysql -u$username -p$password <<QUERY_INPUT | |
USE $db_name; | |
SET foreign_key_checks=0; | |
SET unique_checks=0; | |
SET sql_log_bin=0; | |
SET autocommit=0; | |
LOAD DATA LOCAL INFILE '$csv_filename' INTO TABLE $table_name | |
FIELDS TERMINATED BY ',' | |
LINES TERMINATED BY '\n'; | |
COMMIT; | |
SET sql_log_bin=1; | |
SET unique_checks=1; | |
SET foreign_key_checks=1; | |
SET autocommit=1; | |
QUERY_INPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment