tMysqlConnection - 6.3

Talend Components Reference Guide

Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Talend Studio
Data Governance
Data Quality and Preparation
Design and Development


Opens a connection to the database for a current transaction.


This component is used to open a connection to the specified database that can then be reused in the subsequent subjob or subjobs.

tMysqlConnection Properties

Component family



Basic settings

Property type

Either Built-in or Repository.

Since version 5.6, both the Built-In mode and the Repository mode are available in any of the Talend solutions.



Built-in: No property data stored centrally.



Repository: Select the repository file in which the properties are stored. The fields that follow are completed automatically using the data retrieved.



Database server IP address.



Listening port number of DB server.



Name of the database.


Additional JDBC parameters

Specify additional connection properties for the DB connection you are creating.


Username and Password

DB user authentication data.

To enter the password, click the [...] button next to the password field, and then in the pop-up dialog box enter the password between double quotes and click OK to save the settings.


Use or register a shared DB Connection

Select this check box to share your connection or fetch a connection shared by a parent or child Job. This allows you to share one single DB connection among several DB connection components from different Job levels that can be either parent or child.


This option is incompatible with the Use dynamic job and Use an independent process to run subjob options of the tRunJob component. Using a shared connection together with a tRunJob component with either of these two options enabled will cause your Job to fail.

Shared DB Connection Name: set or type in the shared connection name.

  Specify a data source alias

Select this check box and specify the alias of a data source created on the Talend Runtime side to use the shared connection pool defined in the data source configuration. This option works only when you deploy and run your Job in Talend Runtime. For a related use case, see Scenario 4: Retrieving data from a MySQL database using the data source on Talend Runtime side to set up the database connection.

Advanced settings

Auto Commit

Select this check box to commit any changes to the database automatically upon the transaction.

With this check box selected, you cannot use the corresponding commit component to commit changes to the database; likewise, when using the corresponding commit component, this check box has to be cleared. By default, the auto commit function is disabled and changes must be committed explicitly using the corresponding commit component.

Note that the auto commit function commits each SQL statement as a single transaction immediately after the statement is executed while the commit component does not commit only until all of the statements are executed. For this reason, if you need more room to manage your transactions in a Job, it is recommended to use the commit component.


tStatCatcher Statistics

Select this check box to gather the job processing metadata at a Job level as well as at each component level.


This component is more commonly used with other tMysql* components, especially with the tMysqlCommit and tMysqlRollback components.


If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at



Scenario 1: Inserting data in mother/daughter tables

The following Job is dedicated to advanced database users, who want to carry out multiple table insertions using a parent table id to feed a child table.

As a prerequisite to this Job, follow the steps described below to create the relevant tables using an engine such as innodb:

  1. In a command line editor, connect to your Mysql server.

  2. Once connected to the relevant database, type in the following command to create the parent table:

    create table f1090_mum(id int not null auto_increment, name varchar(10), primary key(id)) engine=innodb;
  3. Then create the second table:

    create table f1090_baby (id_baby int not null, years int) engine=innodb;

Back in Talend Studio, the Job requires seven components including tMysqlConnection and tMysqlCommit.

Linking the components

  1. Drag and drop the following components from the Palette: a tFileList, a tFileInputDelimited, a tMap, a tMysqlConnection, a tMysqlCommit and two tMysqlOutput.

  2. Connect tMysqlConnection to tFileList using an OnComponentOk link.

  3. Connect tFileList to tMysqlCommit using an OnComponentOk link.

  4. Connect the tFileList component to the input file component using an Iterate link as the name of the file to be processed will be dynamically filled in from the tFileList directory using a global variable.

  5. Connect the tFileInputDelimited component to the tMap and dispatch the flow between the two output Mysql DB components. Use a Row link for each for these connections representing the main data flow.

Configuring the components

  1. Set the tFileList component properties, such as the directory name where files will be fetched from.

  2. In the tMysqlConnection Component view, set the connection details manually or fetch them from the Repository if you centrally stored them as a Metadata DB connection entry. For more information about Metadata, see Talend Studio User Guide.

  3. On the tFileInputDelimited component's Basic settings panel, press Ctrl+Space bar to access the variable list. Set the File Name field to the global variable: tFileList_1.CURRENT_FILEPATH

  4. Set the rest of the fields as usual, defining the row and field separators according to your file structure.

  5. Then set the schema manually through the Edit schema feature or select the schema from the Repository. In Java version, make sure the data type is correctly set, in accordance with the nature of the data processed.

  6. In the tMap Output area, add two output tables, one called mum for the parent table, the second called baby, for the child table.

    Drag the Name column from the Input area, and drop it to the mum table.

    Drag the Years column from the Input area and drop it to the baby table.

  7. Make sure the mum table is on the top of the baby table as the order is determining for the flow sequence hence the DB insert to perform correctly.

    Connect the output row link to distribute correctly the flow to the relevant DB output component.

  8. In each of the tMysqlOutput components' Basic settings panel, select the Use an existing connection check box to retrieve the tMysqlConnection details.

  9. Set the Table name making sure it corresponds to the correct table, in this example either f1090_mum or f1090_baby.

    There is no action on the table as they are already created.

    Select Insert as Action on data for both output components.

    Click on Sync columns to retrieve the schema set in the tMap.

  10. In the Additional columns area of the DB output component corresponding to the child table (f1090_baby), set the id_baby column so that it reuses the id from the parent table.

  11. In the SQL expression field type in: "(Select Last_Insert_id())"

    The position is Before and the Reference column is years.

    In the Advanced settings panel, clear the Extend insert check box.

Executing the Job

  1. Press Ctrl + S to save your Job.

  2. Press F6 to execute it.

    The parent table id has been reused to feed the id_baby column.

Scenario 2: Sharing a database connection between a parent Job and child Job

This scenario shows how a database connection is shared between a parent Job and a child Job. The parent Job first calls the child Job to write some randomly generated data to a MySQL database, and then reads the data from the MySQL database and displays it on the console. A connection to the MySQL database is set up only once and used in both Jobs.

Setting up the child Job

Adding and linking components

  1. Add the following components by typing the component names on the design workspace or dropping them from the Palette:

    • a tMysqlConnection component, to open a connection to the MySQL database,

    • a tRowGenerator, to generate random input data,

    • a tMysqlOutput component, to write data to the MySQL database.

  2. Connect the tRowGenerator component to the tMysqlOutput component using a Row > Main connection.

  3. Connect the tMysqlConnection component to the tRowGenerator using a Trigger > OnSubjobOk connection.

Configuring the database connection

  1. Double-click the tMysqlConnection component to open its Basic settings view.

  2. With the Property Type set to Built-In, specify the connection details in the relevant fields, including:

    • the host name or IP address of your database server

    • the listening port number

    • the database name

    • the user name and password for your database authentication.

    If you have stored your connection details under the Metadata node in the Repository tree view, you can simply drop your centralized metadata item onto the tMysqlConnection component. For information on how to centralize a database connection, see the chapter on managing metadata of the Talend Studio User Guide.

  3. Select the Use or register a shared DB Connection check box so that the database connection open by this component can be shared across different Jobs. Then, enter a name for the shared connection between double quotes in the Shared DB Connection Name field, shared_mysql_connection in this example.

Configuring the input data

  1. Double-click the tRowGenerator component to open the Row Generator editor.