I did setup of a MySQL database on AWS free instance t2 micro by following the link: https://towardsdatascience.com/running-mysql-databases-on-aws-ec2-a-tutorial-for-beginners-4301faa0c247
Now I am able to connect to database using MySql Workbench and SSH with pem file.
But What should be the connection string in my code to connect to ec2 instace based my sql database?
I’ve trid this format:
"Server=ec2-xyz.compute-1.amazonaws.com;Port=3306;Database=test;User ID=root;Password=test;"
I am getting this error when I try to access it from .NET Core API: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts
2
Answers
Have you tried a format like this, where it specifies UID and PWD instead of UserId and Password? The connection string syntax may be picky about those names.
You need to connect it via ssh. I found this article that explains how to connect to an ec2 instance through ssh. You will need "Renci SSH.NET" and "MySQLConnector" NuGet packages. https://mysqlconnector.net/tutorials/connect-ssh/
Hope this helps!