IBM Cloud Docs
Connecting with mysql

Connecting with mysql

You can access your MySQL database directly from its command-line client, mysql. You can use mysql for direct interaction and monitoring of the data structures that are created within the database. It is also useful for testing and monitoring the queries and performance, installing and modifying scripts, and other management activities.

Set the admin password before you use it to connect to the database. For more information, see Setting the Admin Password.

Installing mysql

Install the command-line client for MySQL, mysql. To use mysql, the MySQL client tools need to be installed on the local system. They can be installed with the full MySQL package that is provided from mysql.com, or as a package from your operating system's package manager.

For more information about mysql, see the MySQL documentation.

mysql Connection Strings

Connection strings are displayed in the Endpoints panel of your deployment's Overview, and can also be retrieved from the Cloud Databases CLI plug-in, and the API.

The information that you need to make a connection with mysql is in the "cli" section of your connection strings. The table contains a breakdown for reference.

Table 1. mysql/cli connection information
Field Name Index Description
Bin The recommended binary to create a connection; in this case, it is mysql.
Composed A formatted command to establish a connection to your deployment. The command combines the Bin executable file, Environment variable settings, and uses Arguments as command-line parameters.
Environment A list of key/values you set as environment variables.
Arguments 0... The information that is passed as arguments to the command shown in the Bin field.
Certificate Base64 A self-signed certificate that is used to confirm that an application is connecting to the appropriate server. It is base64 encoded.
Certificate Name The allocated name for the self-signed certificate.
Type The type of package that uses this connection information; in this case cli.
  • 0... indicates that there might be one or more of these entries in an array.

Connecting

The ibmcloud cdb deployment-connections command handles everything that is involved in creating a command-line client connection. For example, to connect to a deployment named "example-mysql", use the following command.

ibmcloud cdb deployment-connections example-mysql --start

Or

ibmcloud cdb cxn example-mysql -s

The command prompts for the admin password and then runs the mysql command-line client to connect to the database.

If you have not installed the cloud databases plug-in, connect to your MySQL databases by using mysql by giving it the "composed" connection string. It provides environment variables MYSQL_PWD and --ssl-ca=<cert_name>. Set MYSQL_PWD to the admin's password and --ssl-ca=<cert_name> to the path or file name for the self-signed certificate.

MYSQL_PWD=$PASSWORD mysql --host=e4ad919f-59b6-4300-97c9-e099a5b6cf31.c5kmhkid0ujpmrucb800.databases.appdomain.cloud --port=32195 --user=$USERNAME --ssl-mode=VERIFY_IDENTITY --ssl-ca=52b78cf7-b17e-42aa-9e07-1fe4f741b286 ibmclouddb

Using the self-signed certificate

  1. Copy the certificate information from the Endpoints panel or the Base64 field of the connection information.
  2. If needed, decode the Base64 string into text.
  3. Save the certificate to a file. (You can use the Name that is provided or your own file name).
  4. Provide the path to the certificate to the --ssl-ca=<cert_name> environment variable.

You can display the decoded certificate for your deployment with the CLI plug-in with the command:

ibmcloud cdb deployment-cacert "your-service-name"

It decodes the base64 into text. Copy and save the command's output to a file and provide the file's path to the --ssl-ca=<cert_name> environment variable.