Friday 22 April 2022

Sqoop eval: Execute a query on a database

‘sqoop-eval’ command is used to execute a query on a database.

 

Syntax

sqoop-eval --connect "{jdbc_connection_url}" --username "{user_name}" --password "{password}" --query "{queryToExecute}"
 

You can even use the option -e instead of –query option.

sqoop-eval --connect "{jdbc_connection_url}" --username "{user_name}" --password "{password}" -e "{queryToExecute}"

 

Example

sqoop-eval --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "retail_dba" --password "cloudera" --query "SELECT * FROM orders LIMIT 5"

 

$sqoop-eval --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "retail_dba" --password "cloudera" --query "SELECT * FROM orders LIMIT 5"
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
22/03/31 04:17:58 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.13.0
22/03/31 04:17:58 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
22/03/31 04:17:59 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
--------------------------------------------------------------------------
| order_id    | order_date          | order_customer_id | order_status         | 
--------------------------------------------------------------------------
| 1           | 2013-07-25 00:00:00.0 | 11599       | CLOSED               | 
| 2           | 2013-07-25 00:00:00.0 | 256         | PENDING_PAYMENT      | 
| 3           | 2013-07-25 00:00:00.0 | 12111       | COMPLETE             | 
| 4           | 2013-07-25 00:00:00.0 | 8827        | CLOSED               | 
| 5           | 2013-07-25 00:00:00.0 | 11318       | COMPLETE             | 
--------------------------------------------------------------------------

 



 

Using -e option


sqoop-eval --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "retail_dba" --password "cloudera" -e "SELECT * FROM orders LIMIT 5"
[cloudera@quickstart Desktop]$ sqoop-eval --connect "jdbc:mysql://quickstart.cloudera:3306/retail_db" --username "retail_dba" --password "cloudera" -e "SELECT * FROM orders LIMIT 5"
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
22/04/01 01:54:32 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.13.0
22/04/01 01:54:32 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
22/04/01 01:54:33 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
--------------------------------------------------------------------------
| order_id    | order_date          | order_customer_id | order_status         | 
--------------------------------------------------------------------------
| 1           | 2013-07-25 00:00:00.0 | 11599       | CLOSED               | 
| 2           | 2013-07-25 00:00:00.0 | 256         | PENDING_PAYMENT      | 
| 3           | 2013-07-25 00:00:00.0 | 12111       | COMPLETE             | 
| 4           | 2013-07-25 00:00:00.0 | 8827        | CLOSED               | 
| 5           | 2013-07-25 00:00:00.0 | 11318       | COMPLETE             | 
--------------------------------------------------------------------------
[cloudera@quickstart Desktop]$

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment