-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-sqoop.sh
65 lines (52 loc) · 1.88 KB
/
run-sqoop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
sudo apt update
sudo apt-get install -y mysql-server git
# Check mysql service running
SERVICE="mysql"
# Check the status of the MySQL service
if systemctl is-active --quiet $SERVICE; then
echo "$SERVICE service is running."
else
echo "$SERVICE service is not running. Attempting to start $SERVICE..."
# Try to start the service
sudo systemctl start $SERVICE
# Check if the service started successfully
if systemctl is-active --quiet $SERVICE; then
echo "$SERVICE service has been started successfully."
else
echo "Failed to start $SERVICE service."
fi
fi
# Prepare sql script
cat << EOF > /tmp/prepare.sql
CREATE DATABASE WQD7007;
USE WQD7007;
CREATE TABLE churn (customerID varchar(20), PaperlessBilling varchar(3), PaymentMethod varchar(30), MonthlyCharges numeric(8,2), Churn varchar(3));
SET GLOBAL local_infile=true;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;
EOF
# Create mysql database
sudo mysql -uroot -proot < /tmp/prepare.sql
# Import dataset into the dataset
sudo mysql -uroot -proot --local_infile=1 WQD7007 \
-e \
"LOAD DATA LOCAL INFILE './dataset/churn_reduced.csv' INTO TABLE churn FIELDS TERMINATED BY ','"
# Download Hive
wget -O /tmp/sqoop-1.4.7.tar.gz https://archive.apache.org/dist/sqoop/1.4.7/sqoop-1.4.7.tar.gz
tar -xzf /tmp/sqoop-1.4.7.tar.gz
cp -r sqoop-1.4.7 $HOME/sqoop/
# Export path
echo "export PATH=$PATH:$HOME/sqoop/bin" >> ~/.bashrc
echo "HADOOP_COMMON_HOME=$HOME/hadoop" >> ~/.bashrc
echo "HADOOP_MAPRED_HOME=$HOME/hadoop" >> ~/.bashrc
source ~/.bashrc
# Update template
mv -f $HOME/sqoop/conf/sqoop-env-template.sh $HOME/sqoop/conf/sqoop-env.sh
# Copy connector
cp ./connector/mysql-connector-java-5.1.47.jar $HOME/sqoop/lib
sqoop import -connect jdbc:mysql://localhost/WQD7007 \
-username root \
-password root \
-table churn -m 1
hdfs dfs -cat $HOME/churn/*