Connect using the CLI for Public Cloud Databases for MySQL
Objective
Public Cloud Databases allow you to focus on building and deploying cloud applications while OVHcloud takes care of the database infrastructure and maintenance in operational conditions.
This guide explains how to connect to a MySQL database instance with a Command Line Interface (CLI).
Requirements
- Access to the OVHcloud Control Panel
- A Public Cloud project in your OVHcloud account
- A MySQL database running on your OVHcloud Public Cloud Databases (this guide can help you to meet this requirement)
- Configure your MySQL instance to accept incoming connections
Concept
To interact correctly with the MySQL instance, we need to first install something called a MySQL client, in order to connect and control the MySQL service remotely. It's a Client-Server interaction.
Instructions
Installing the MySQL client
Please note that a MySQL client is natively integrated in the MySQL software package but it does not allow the use of Service URI.
You first need to install a software to interact with your MySQL instance remotely. This official software can be installed on various client machines such as your own computer, a VPS or a virtual machine. The only rule is to be able to reach the public network (Internet) and have sufficient rights to install it.
In order to do so and depending on your configuration, you may need to follow official MySQL documentation to install MySQL Shell (mysqlsh), more powerful compared to MySQL Client (mysql).
MySQL Shell is not mandatory but much more convenient to use compared to standard MySQL Clients, since you can connect with Service URI instead of individual parameters.
Follow the steps here after selecting Windows, MacOS or Linux as operating system: https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install.html
We are now ready to learn how to connect to our MySQL instance.
Configuration
We will now follow official MySQL documentation to perform our first connection.
In your CLI, type mysqlsh --version. The result should look like this:
It means that mysqlsh is correctly installed and working properly. If you do not see something like this result, please go back to the previous step and reinstall MySQL shell.
Connect to your MySQL instance
We will follow official MySQL documentation: https://dev.mysql.com/doc/refman/8.0/en/connecting-using-uri-or-key-value-pairs.html.
To perform a connection, simply type mysqlsh --sql followed by the Service URI:
Don't forget you need to modify the username, password, hostname and port. In our example, it will look like this:
Once connected correctly, you should see something similar to:
Congratulations! You are now fully able to interact with your MySQL instance!
MySQL client usage
Once connected, you can manage your MySQL instance with built-in MySQL client methods.
Please follow the official MySQL documentation.
To verify:
SHOW DATABASES;will list all the databases;select * from mysql.user;will display information about existing users.
In our example, it will look like this:
Go further
Getting started with Public Cloud Databases
Visit the Github examples repository to find how to connect to your database with several languages.
We want your feedback!
We would love to help answer questions and appreciate any feedback you may have.
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our databases service!