Guest User

Untitled

a guest
Nov 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$#" -ne 5 ]; then
  4. echo "Wrong number of arguments to the import shell script."
  5. exit 1
  6. fi
  7.  
  8. csv_filename=$1
  9. table_name=$2
  10. db_name=$3
  11. username=$4
  12. password=$5
  13.  
  14. mysql -u$username -p$password <<QUERY_INPUT
  15. USE $db_name;
  16. DROP TABLE IF EXISTS temp_table;
  17. CREATE TABLE temp_table LIKE $table_name;
  18. ALTER TABLE temp_table DROP COLUMN date_of_birth;
  19. SET foreign_key_checks=0;
  20. SET unique_checks=0;
  21. SET sql_log_bin=0;
  22. SET autocommit=0;
  23. LOAD DATA LOCAL INFILE '$csv_filename' INTO TABLE temp_table
  24. FIELDS TERMINATED BY '^'
  25. LINES TERMINATED BY '\n';
  26. COMMIT;
  27. UPDATE $table_name AS Original
  28. INNER JOIN temp_table AS New USING(id)
  29. SET Original.name = New.name;
  30. COMMIT;
  31. DROP TABLE temp_table;
  32. COMMIT;
  33. SET sql_log_bin=1;
  34. SET unique_checks=1;
  35. SET foreign_key_checks=1;
  36. SET autocommit=1;
  37. QUERY_INPUT
Add Comment
Please, Sign In to add comment