Connect to MySQL
Connects with a MySQL database.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
Establishes a connection with a MySQL server database.
Dependencies
- You need a valid connection string to connect to the MySQL database. See the
connectionstring
parameter for examples of valid connection strings. - You must install The MySQL Connector 8.0.33 or above. See Installing MySQL Connector for instructions on how to install it.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
mysqlConnect --connectionstring(String) (DbConnection)=connection
Input parameter
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Connection String | connectionstring |
Required |
Text |
The Connection string to connect to the MySQL Database. See the connectionstring parameter section for details. |
connectionstring
parameter
The connectionstring
parameter is where you enter the string that includes key-value pairs providing the necessary information to connect to the MySQL database. The following code block is an example of a valid connection string:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
- Server: the address or hostname of the MySQL server.
- Database: The name of the specific database you want to connect to.
- User Id: Specifies the username for authentication.
- Password: Specifies the password for authentication.
Replace each field with your actual MySQL database server credentials and connection details.
Output parameters
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Connection | connection |
Database Connection |
Returns the database connection string. |
Example
This example connects to a MySQL database by using the Assert Condition (assert
) command to verify whether the connection was successful. The message "Could not connect to the Database!"
is displayed if the connection is empty.
defVar --name dbConnection --type DbConnection
// Connect to the bank via the connection string and store it in the connection variable.
mysqlConnect --connectionstring "server=localhost;User Id=root;database=NameDataBase; password=YourPassword" dbConnection=connection
// Checks if the connection was successful
assert --message "Could not connect to the Database!" --left "${dbConnection}" --operator "Is_Null" --negate