Connection string of MySQL database hosted on AWS EC2 instance? - mysql

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

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.
Database=database_name;UID=user_name;PWD=password;Port=port_number;

Related

IAM authentication to connect with any SQL client to Amazon RDS for MySQL

I can connect to the MySQL RDS database using IAM authentication from the SQL command line tool. But the same I need to achieve connections with SQL clients like DBeaver or some other clients. I don't have the provision of passing tokens in SQL client.
This document explains connecting RDS using MySQL workbench/j but I am unable to download the MySQL workbench/j due to a forbidden error. https://aws.amazon.com/blogs/database/use-iam-authentication-to-connect-with-sql-workbenchj-to-amazon-aurora-mysql-or-amazon-rds-for-mysql/
Could someone help me in connecting RDS using IAM authentication from an SQL client?
In fact you could use the aws rds command to generate each time a new token to use as your password to authenticate the database. But since you want to do it with deaver, looks like its available (https://dbeaver.com/docs/wiki/AWS-Credentials/) but only in Enterprise edition (not the community edition)
If you're going to use DBeaver
The proper connection details :
Server Host: Endpoint address
Port: 3306
Database: DB name
User name: Database master username
Password: Database master password
1
2

What is The JDBC connect string for connecting to mysql when SSL certificates are required?

I have a Cloud SQL instance in which I have to enable that SSL certificates are require to connect.
The equivalent MySQL command for connecting to my instance is this
mysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem --host=[INSTANCE_IP] --user=root --password
Now I need an equivalent JDBC connection string for the same.
What Addition parameter should a add to my correct JDBC string?
jdbc:mysql://<server_ip>:3306/<db_name>
If you are using the Cloud SQL Java Connector, you don't need any configuration - SSL/TLS happens automatically.
If you prefer, you can also connect the same way with a regular MySQL database, which involves creating a Java keystore. This blogpost has an example of how to do so.

Remotely connect to an aws-windows instance based MySQL Database

I have launched an AWS EC2 Windows_Server-2016 instance.
Since this server is windows based,I can successfully connect to
it using remote desktop connection by entering the username,
password and a .ppk file.
I have installed MySQL server on the instance and created a user
that is allowed to login with any ip i.e by providing the '%' sign.
Here's what my AWS instance security group looks like :
I have tried connecting to the MySQL server using SQLYOG using 2
different scenarios :
Tried connecting by using the aws public ipv4 address as a host field and
using mysql username & password
Tried connecting by creating an SSH connection i.e providing server
username/password and .ppk file in SSH connection panel & then
providing mysql host/username and localhost in mysql connection
panel
None of the methods used allows me to connect.I try same procedure with a linux based server and can connect successfully. Please let me know where am I going wrong while using a windows based MySQL hosting.
MySQL has an extra level of IP protection for remote clients. You have to GRANT access to the remote ip(your house of office) to be able to connect. As root, you have to do :
GRANT ALL ON <db>.* TO '<username>'#'<remote ip>' IDENTIFIED BY '<remote_password>';
Where is the DB you are trying to connect to etc.

Grant access to a EC2 and RDS instances [duplicate]

I'm using AWS for my project and Laravel 5. Just installed my laravel project in the EC2 and set up a DB in RDS. I imported the .sql file using mysql workbench. In my .env I set up the host, the DB name, user and password but when I go to the project in the browser I get an error:
PDOException in Connector.php line 55:
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'blue*****.************.us-west-2.rds.amazonaws.com' (4)
Put the * for security reasons. So what could be wrong?
Update:
When I tried to connect to the RDS instance using the command line I got:
ERROR 2003 (HY000): Can't connect to MySQL server on 'blue****.**********.us-west-2.rds.amazonaws.com' (110)
The reason you are not able to connect to the RDS instance from the EC2 instance has to do with security group.
Before your EC2 instance can communicate with the RDS server, you need to configure a security group for the RDS.
You can check this and this for more details.

Can't connect a DB to AWS

I'm using AWS for my project and Laravel 5. Just installed my laravel project in the EC2 and set up a DB in RDS. I imported the .sql file using mysql workbench. In my .env I set up the host, the DB name, user and password but when I go to the project in the browser I get an error:
PDOException in Connector.php line 55:
SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'blue*****.************.us-west-2.rds.amazonaws.com' (4)
Put the * for security reasons. So what could be wrong?
Update:
When I tried to connect to the RDS instance using the command line I got:
ERROR 2003 (HY000): Can't connect to MySQL server on 'blue****.**********.us-west-2.rds.amazonaws.com' (110)
The reason you are not able to connect to the RDS instance from the EC2 instance has to do with security group.
Before your EC2 instance can communicate with the RDS server, you need to configure a security group for the RDS.
You can check this and this for more details.