Time for action – setting up the employee database
No discussion of databases is complete without the example of an employee table, so we will follow tradition and start there.
Create a tab-separated file named
employees.tsv
with the following entries:Alice Engineering 50000 2009-03-12 BobSales 35000 2011-10-01 Camille Marketing 40000 2003-04-20 David Executive 75000 2001-03-20 Erica Support 34000 2011-07-07
Connect to the MySQL server:
$ mysql -u hadoopuser -p hadooptest
Create the table:
Mysql> create table employees( first_name varchar(10) primary key, dept varchar(15), salary int, start_date date ) ;
Load the data from the file into the database:
mysql> load data local infile '/home/garry/employees.tsv' -> into table employees -> fields terminated by '\t' lines terminated by '\n' ;
What just happened?
This is pretty standard database stuff. We created a tab-separated data file, created the table in the database, and then used the LOAD DATA LOCAL INFILE...