Below are the steps to connect to a remote database present on MySQL in EC2 Ubuntu instance:
Open MySQL Workbench and click plus icon to add a new connection:
In the add new connection modal, add the following details to connect to the remote database with MySQL Workbench:
- Connection Method: Standard TCP/IP over SSH
- SSH Host Name: <EC2PublicIP>:22
- SSH Username: ubuntu
- SSH Password: Leave this
- SSH Key file: /Users/…/../Ubuntu-Server-Key-Pair.pem
- MySQL Hostname: localhost
- MySQL Server Port: 3306
- Username: <YourMySQLUser>
- Password: <YourMySQLUserPassword>
Detailes of the above settings:
- SSH Host Name is the public IP of your EC2 Ubuntu instance whwre MySQL is installed, example: 18.104.22.168.
- SSH Username: The name of the default user with which default SSH tunneling is allowed, example: ubuntu.
- SSH Password: Leave it as blank.
- SSH Key file: The local path of the private key file to connect to EC2 instance. This is generated when EC2 was created. You need to contact your admin to get that if you doesn’t have that file.
- MySQL Hostname: The server name of MySQL instance, localhost for example. Do not add any public ip here.
- Username: Username of user in MySQL instance.
- Password: Password of MySQL user to connect with.
Click “Test connection” button to test the connection with the settings added above. If all the settings are correct you will be presented with the following screen:
Go to MySQL Workbench home screen and connect to the recent connection which you just created.
You will be succesfully connected to the remote db of MySQL present on EC2 ubuntu server.