0

I have a scenario where I cannot directly access the application database even though I know the host/port/password/user (due to some security groups which I can't change). I can, however, connect to the application instance via ssh: enter image description here

Now I wanted to somehow execute mysql commands on the database instance. I can't seem to understand how.

saran3h
  • 12,353
  • 4
  • 42
  • 54
  • You have Django tagged here ... do you have a working Django app in this instance? If so -- you can run python manage.py dbshell and Django will setup a working SQL connection for you. – yrekkehs Jan 09 '19 at 04:28
  • Yes I do. I think I did try the dbshell command but there was an issue. Let me try again. – saran3h Jan 09 '19 at 04:54
  • @yrekkehs `CommandError: You appear not to have the 'mysql' program installed or on your path.` - I go this error. – saran3h Jan 09 '19 at 05:04

3 Answers3

1

I presume that by "connect" to the application you mean that you can connect to the node in AWS where the application is running. Since your application can access the database from that point, therefore you might also be able to do the same.

This is something of a broad answer, but what you can do is to install a MySQL client program on that node. Then, you would only have to login to MySQL on the command line, and ideally you should be able to access MySQL from there.

Here is a link to another Stack Overflow question which discusses how to install a MySQL client only on a Linux box.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 1
    Wish there could be multiple green checkmarks. harsh's answer was a bit more detailed. Plus, you already have so much rep :P – saran3h Jan 09 '19 at 05:19
1

install mysql-client on instance using instance

If it is Ubuntu instance try

sudo apt-get install mysql-client

or 

yum install mysql-client

and now you can connect to mysql

for that you have to execute

mysql -h "HOSTNAME(RDS Endpoint)" -u "Username(Whatever you have set)" -p "Database Name"

HOLA you are done...!

After successful connection you have to create database if not any database is present or select database if it's already there

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
0

To install the Linux mysql client from yum on AWS, run the next command:

yum install mysql

You can then login with

mysql -h <db-address> -u <username> -p
Calum Halpin
  • 1,945
  • 1
  • 10
  • 20