wiki:jazz/13-12-21

Version 5 (modified by jazz, 11 years ago) (diff)

--

2013-12-21

Sqoop

  • <參考> MySQL 新增使用者
    for ((i=1;i<=30;i++)); do printf "CREATE DATABASE user%02d;\n" $i; done > add_user_db.sql
    mysql -h 主機名稱 -u root -p < add_user_db.sql
    for ((i=1;i<=30;i++)); do printf "GRANT SELECT,INSERT,UPDATE ON user%02d.* TO 'user%02d'@'%s' IDENTIFIED BY '密碼';\n" $i $i '%'; done > add_user.sql
    echo "FLUSH PRIVILEGES;" >> add_user.sql
    mysql -h 主機名稱 -u root -p < add_user.sql
    
  • 建立 MySQL 測試資料庫
    mysql> use test;
    mysql> show tables;
    mysql> create table mysql_data(id int primary key, name varchar(50));
    mysql> show tables;
    
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | mysql_data     |
    +----------------+
    1 row in set (0.01 sec)
    
    mysql> insert into mysql_data values (1, 'Hello');
    mysql> insert into mysql_data values (2, 'World');
    
    mysql> select * from mysql_data;
    +----+-------+
    | id | name  |
    +----+-------+
    |  1 | Hello |
    |  2 | World |
    +----+-------+
    2 rows in set (0.01 sec)資料庫名
    
  • 建立測試帳號
    mysql> GRANT SELECT,INSERT,UPDATE ON 資料庫名.* TO user@host IDENTIFIED BY '密碼';
    mysql> FLUSH PRIVILEGES;
    
  • 執行 Sqoop 連到 MySQL 匯入資料的測試
    jazz@master ~ $ sqoop import --connect jdbc:mysql://sql.3du.me/test --table mysql_data --username sqoop -P
    jazz@master ~ $ hadoop fs -cat mysql_data/part-m-00000