Using Service Connectors with MySQL
This tutorial takes you through setting up a .NET Core application with the MySQL service connector.
Note
For more detailed examples, please refer to the MySql project in the Steeltoe Samples Repository.
First, start a MySQL instance using the Steeltoe dockerfile.
docker run --env MYSQL_ROOT_PASSWORD=Steeltoe456 --publish 3306:3306 steeltoeoss/mysql
Next, create a .NET Core WebAPI that interacts with MySQL
Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr
Name the project "MySqlConnector"
Add the "MySQL" dependency
Click Generate to download a zip containing the new project
Extract the zipped project and open in your IDE of choice
Set the instance address in appsettings.json
{ "mysql": { "client": { "server": "127.0.0.1", "port": "3306", "username": "root", "password": "Steeltoe456" } } }
Tip
Looking for additional params to use when connecting? Have a look at the docs
Run the application
dotnet run <PATH_TO>\MySqlConnector.csproj
Navigate to the endpoint (you may need to change the port number) http://localhost:5000/api/values
Once the app loads in the browser you will see a list of the default schema info installed with MySQL. "["CHARACTER_SETS","COLLATIONS","COLLATION_CHARACTER_SET_APPLICABILITY", "COLUMNS","COLUMN_PRIVILEGES" ..." *In cloud foundry this information is cleared. The app will return an empty collection "[]".