Accessing a database using the AWS CloudShell

0

I am not a programmer, and I only have very limited understanding of what I'm doing here, but I'm trying to restart a project that lapsed a year or so ago on my own and I need to access a database formerly created (not by me!) on AWS. I understand that the command is:

mysql -u "user name" -h "host-name" -p

However, I do not have a record of the user name and host name. Apparently, I should be able to access that information with the following path:

/var/www/html/application/settings/database.php

But all I get is:

-bash: /var/www/html: No such file or directory

Does anyone have any ideas of where I can go from here? Thank you.

jyamamo
asked 2 months ago208 views
5 Answers
1

Hello.

I think you were probably connecting to the database using EC2 or something rather than within CloudShell.
Also, do you have RDS within your AWS account?
If you can confirm that the instance exists in the RDS console, you can check the host option of the "mysql" command.
Also, if you can find an RDS instance, you can change the password by following the steps in the document below.
https://repost.aws/knowledge-center/reset-master-user-password-rds

profile picture
EXPERT
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
  • Was it possible to connect to the database with CloudShell a year ago? By the way, data in CloudShell will be deleted 120 days after it was last accessed, so if it has not been accessed for a long time, the php file "database.php" may have disappeared. https://docs.aws.amazon.com/cloudshell/latest/userguide/limits.html

    If you stop using AWS CloudShell in an AWS Region, data is retained in the persistent storage of that Region for 120 days after the end of your last session.

    Also, are you viewing the correct region? RDS is a regional resource and may be found if you open another region. https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/select-region.html

  • It is also possible that the database is in an instance such as EC2 or Lightsail that hosts the website without using RDS. Please check whether EC2 or Lightsail exists in your AWS account. Can you find the file by running the command below? If it cannot be found, the CloudShell data may have disappeared or the CloudShell region may be incorrect.

    ls -la /var/www/html/application/settings/
    

    I'm attempting to get support from the people who set this up initially, but it's proving difficult.

    It's probably best to contact the person who created the project directly, as further information may not be available on re:Post.

1

As @Riku_Kobayashi has already said, the file /var/www/html/application/settings/database.php is almost certainly not in CloudShell but more likely in an EC2 instance (this is basically a VM in the cloud).

I notice that your CloudShell link & screengrab are for the AWS Region ap-northeast-1 (Tokyo) but the RDS link in the text is ap-southeast-2 (Sydney). Usually you would expect resources to be provisioned in the same region, and for this to be geographically close to your location. Which would this be for you?

If there is an EC2 instance running in this account anywhere in the world you should be able to identify it in EC2 Global View https://console.aws.amazon.com/ec2globalview/home#

Once you find it then navigate to the region in which it is running https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/select-region.html

Depending on the AMI it's built with you may be able to connect to it using EC2 Instance Connect https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html

Or Session Manager https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/session-manager-to-linux.html

From here you can display the contents of the database.php file (check beforehand it is an ASCII text file).

ls -l /var/www/html/application/settings/database.php
file /var/www/html/application/settings/database.php
cat /var/www/html/application/settings/database.php

And it would be a fair assumption that whichever region this EC2 is in, the RDS database is likely to be in the same one.

profile picture
EXPERT
Steve_M
answered 2 months ago
0

Many thanks, Gary, Riku & Steve!

Yes, I am attempting to get support from the developer, but it's proving difficult. Riku's suggestion to access EC2 Global View was helpful, and it shows an instance: EC2 Global View Clicking through to the instance details and "Connect" I get the following, in the Ohio region: Ubuntu However, I can't follow the path "/var/www/html " >> "application/settings/" >> "database.php" >. Path I'm not sure where to take it from there. thank you for getting me this far!

jyamamo
answered 2 months ago
  • Typing /var/www/html/application/settings/database.php by itself will cause the shell to try and run it (which it almost certainly can't).

    Verify that the file exists: ls -l /var/www/html/application/settings/database.php

    Verify the file type: file /var/www/html/application/settings/database.php

    If it's ASCII text then display the contents: cat /var/www/html/application/settings/database.php

  • And separate to EC2, do you see any RDS databases in Ohio? https://us-east-2.console.aws.amazon.com/rds/home?region=us-east-2#

0

Hi, Steve_M. Thank you for the advice.

Following the steps you suggested I can get this far: Console commands

Everything in Ohio shows up as 0.

jyamamo
answered 2 months ago
  • Okay so the host is localhost, which suggests the database is running locally on this EC2 instance, and not in RDS.

    Check that MySQL is running and listening on the default port sudo netstat -tulpn | grep -w 3306

    If it is then try to connect, plugging in the parameters from database.php into the mysql command that's in your original question.

    More info on the Ubuntu mysql command is here https://manpages.ubuntu.com/manpages/trusty/man1/mysql.1.html

  • I got caught up with other things and still haven't resolved this.

    I entered sudo netstat -tulpn | grep -w 3306 at the Ubuntu search prompt, but the response was "command not found". Entering mysql got the response "Access denied for user 'ubuntu' @ 'localhost' (using password: NO)'. I feel I'm getting closer, but still not quite there!

0

Thank you for your reply. Unfortunately, I am not familiar with the technology and the terms you are using (EC2, RDS...). I am attempting to enter commands here: https://ap-northeast-1.console.aws.amazon.com/cloudshell/home?region=ap-northeast-1#1657521f-ffb3-482e-b3c6-3dcc5d06ffc0. I log in and enter /var/www/html/application/settings/database.php, but it doesn't work.

Screenshot of Console

I successfully accessed the database about a year ago, but have been drawn away from this project by other things and on coming back to it I can't make it work.

On thing, though; the database link (https://ap-southeast-2.console.aws.amazon.com/rds/home?region=ap-southeast-2#) says there are no instances of any database. This is odd, because the site itself is performing as normal, including material which I believe is inside at least one database.

I'm attempting to get support from the people who set this up initially, but it's proving difficult.

jyamamo
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions