Login to EC2 server to create MySQL database - mysql

I had a friend create an AWS account and an EC2 instance after which he gave me the username and password to login. I am having a lot of trouble getting into the server with the information he gave me. I'm new to amazon services so I'm not sure if I'm doing something wrong or not. I seem to be able to login using PuTTy, but it doesn't prompt me for a password, I just get through with the username alone. copying the ip into a browser just gets me a "This webpage is not available"
message. He also gave me the key file but I'm sure where to use it.
Anyone know how I can get into the server to modify the database?

If there is a message 'This webpage is not available' then it could be there is no HTTP server running on port 80, or the security group configured on the EC2 instance is set to deny connections to port 80. If it is a new instance, there probably isn't a firewall configured locally to deny connections.
If you are sure there is a server running on port 80, you can use these instructions to tunnel through SSH
Set up your PuTTY window like this, and hit the Add button
Navigate to http://127.0.0.1 and you should see the web server if there is one running, if you can navigate using this way, you have a problem with your security group configuration. If you cannot, you do not have a HTTP server running to connect to. If there is not one running (and I am assuming you wish to use phpMyAdmin), you may have to set up apache and install phpMyAdmin
As you connect without a password, do you receive a line along the lines of
'Authenticating with public key "unipc-rpi"' or mentioning 'Pageant', because it means that instead of a password, PuTTY is authenticating using a public key and not a password.

Related

Can't connect to MySQL server on AWS. AWS says access denied to client and replaces the AWS hostname with local IPv4 address

I am unable to access an AWS server on various software -- Microsoft Remote Desktop, MySQLWorkbench and DBeaver. The credentials are correct and the same as those of my teammates and they are able to access the server. It resolves the hostname to be the IP address and not the host address, which is strange. In the dialog box attached, it should say that Access is denied to admin# but it says admin instead.
I have tried uninstalling and installing MySQLWorkbench multiple times. I uninstalled and installed the mysql library. I have tried changing the my.cnf files but that doesn't help either. I have a suspicion that it may be something on the server-side (AWS). I looked at the AWS console and it allows access to all IP addresses. I have tried a lot of things and still face the issue of the hostname being resolved to the local IP.
Can you please help me out?
enter image description here

Finding MySQL localhost URL and/or accessing phpmyadmin

Going around in circles. Please help, I enter http://localhost into safari on my mac and receive: It works!
However, I cannot figure out how using MySQL workbench I can find the URL. I am looking to code JSON in xCode to retrieve data from my local MySQL database, however, I do not even know the URL to access it.
My port is on 3306. I have tried http://127.0.0.1:3306 - and get a failed to open.
Do I need myphpadmin or can I go direct to MySQL?
I have tried saving a copy of MyPhPAdmin under Users>MyUserName> but this did not work when I ran: http://localhost/myphpadmin
Should the file be saved elsewhere? When I worked on Python weeks ago I run it under a different location then was recommended (Under the Python X.X cache folder) whereas online people simply ran it from their Users>MyUserName> folder. I am on the latest Catalina OS X.
Tried http://localhost/usr/local/mysql-8.0.20-macos10.15-x86_64/phpmyadmin/ - 404 not found
With MySQL, you can connect via localhost "socket" or networking "TCP/IP" connections. The user accounts in MySQL exist separately from each other, so if your user account exists with host value 'localhost' the TCP/IP connection probably won't work for you. Also note that, depending on how you installed MySQL and how it's configured, it might not even listen for network connections. Normally, localhost is preferred if you are on the same machine.
In MySQL Workbench, you need to give the hostname or IP address when selecting "Standard (TCP/IP)" from the "Connection Method" dropdown. This is simply the hostname or IP address, not a complete URL or web site. So you'd set the hostname to "127.0.0.1" or "192.168.9.34" or whatever. Again, Local Socket/Pipe is usually a better choice in most cases.
MySQL uses its own networking port (3306) and communication protocol, so using http://127.0.0.1 is incorrect as it isn't using the http protocol. Likewise, if you would need to change the port for some reason, specify that in the port field rather than as a part of the hostname.
As for phpMyAdmin, you would install that to a folder that is handled by your web server, then access it through the URL/path exposed by the web server — by default, your user home directory is not shared to the web (and rightly so, I don't want all of my documents and files shared with the world!). Put the phpMyAdmin folder in your web root and you'll have better success. Which folder that is probably depends a lot on which webserver you are running, how it is installed, and how you configured it.
I won't comment on the Python scripts you've run in the past, as my experience with serving Python to the web requires adjusting some settings in my nginx configuration and I won't want to confuse you compared to the tutorials you're following.

PHP MyAdmin Azure App Services - (HY000/2002): An attempt was made to access a socket in a way forbidden by its access permissions

When attempting to connect to the Azure App Services (ASP.NET) MySQL database (Navigating to the Manage link) the Page info returned from PHPMyAdmin prevents me from moving forward. I cannot seem to find the location of the log for the app within Kudu and navigating to the MYSQLCONNSTR_*.ini file did not provide me with the information that I needed.
I've attempted to use the connection strings for the database for both the scm and the web app but neither work. I have also attempted to use the public-facing IP within the Kudu environment variable without any luck.
I cannot seem to find the information I need to connect to my instance of PHPMyAdmin, and am now quite lost.
The solution to my problem was here: https://stackoverflow.com/a/57545678/4212591
The free tier of the Azure Web Service does not allow for the always-on feature. Thus my inability to connect to the service.
I’m unsure on the exact location/path you are looking for that file, the connection string is stored at D:\home\data\mysql\MYSQLCONNSTR_localdb.txt.
If you wish to customize the database, username and password, after you have created a new database, add new username or update password, simply modify:
D:\home\data\mysql\MYSQLCONNSTR_localdb.ini , remove D:\home\data\mysql\MYSQLCONNSTR_localdb.txt and restart the WebApps.
Furthermore, the connection string flows to your application as an env variable MYSQLCONNSTR_localdb. The env is added to the main site process. For Kudu site, one may read the same info from D:\home\data\mysql\MYSQLCONNSTR_localdb.txt file. Beware that we are not using the default MySql port (3306). In fact, the port number may vary for each application life cycle depending on its availability at startup time. The port info is also available as an env variable WEBSITE_MYSQL_PORT to your site.
Ensure that MySQL process is running. Check in your web app application settings if there is a connection string. PHPmyadmin uses MYSQLCONNSTR_ to connect to the MySQL server. If you have a connection string in application setting change the connection string type to Custom , so you can still have the information if needed or delete it. This will force PHPmyadmin to access MYSQLCONNSTR_localdb and connect to the MySQL in-app server.
As a side note, on Azure WebApps Sandbox - Connection attempts to local addresses (e.g. localhost, 127.0.0.1) and the machine's own IP will fail, except if another process in the same sandbox has created a listening socket on the destination port.
To rule out, application code or the client library leaking TCP socket handles or burst load of requests opening too many TCP socket connections at once, scale-up Azure App Service Plan and see if that makes any difference.

Using SSH tunnel to connect to remote MYSQL database from Node-Red

I have a set of data rolling out of Node-Red that I want to send to a remote MYSQL database. The Node-Red system is running on a Raspberry Pi. How do I make this work? I know how to it using Node.JS but im not sure how to do this in Node-Red. The IP-adress of the Pi is dynamic so simply authorizing its Ip address does not work sadly.
Thanks in advance!
EDIT for clarification:
I want to connect to a remote MYSQL database that is hosted by my webhosting. I have connected a Raspberry Pi to a battery, and I want to save this information in the aforementioned database. Since there will be several battery setups in different locations, I cannot save the data locally. So, one way or another I need to access the remote database through Node-Red. Authorizing one IP-address does't work, since the IP of the Raspberry Pi network is dynamic and thus changes. I think a SSH-Tunnel might be the solution, but I have no idea how to this in Node-Red, and google isnt very helpful.
OK, so as I said in the comments you can make a Username/Password pair for MySQL can be granted permission to any IP address (which is less secure if the username/password is compromised. Set the host to '%' to allow all hosts when setting up the grant options).
To reduce the risk you can restrict the Username/Password to a specific subnet. This could be a wifi network or the subnet associated to the piblic IP (it needs to be the public range as nearly all cellular ISPs use CGNAT) range of the cellular provider you may be using. (See this question for details How to grant remote access to MySQL for a whole subnet?).
If you want to use a SSH tunnel then this will normally be done outside Node-RED with the ssh command line e.g.
ssh -L localhost:3306:localhost:3306 remote.host.com
Then configure the Node-RED MySQL node to point to localhost.
Since the connection will look like it's coming from localhost on the MySQL machine you need make sure the Username/Password is locked down to a that host.
You will probably also want to set up public/private key authentication for the ssh connection.
You may be able to run the ssh command in the node-red-daemon node, which should restart the connection if it gets dropped.

No sql server database connection with localy used IIS

i am trying to get a database connection through my IIS with an MVC Webproject.
In my Web.conf connection string i use following parameters:
data source=[Computername]\[DatabaseInstanceName]
This doesn't work for me.But when change the [Computername] to my IP-Adress it works.
Somebody with an idea what i can do? Because it's annoying to change this everyday in several files.
edit: i am using the IIS 8
There are several ways I verify my connection
1) If you are using visual studio,
a) on the Data menu click on Transact-SQL Editor and check this dialog
b) Another trick is I try to create a datasource, follow the dialog box and copy the connection string that Visual Studio generate
c) If look at the Server Explorer and you can find your database there, right click the database and click Properties
The computername needs to be accessible to the machine. Currently only the IP address works because nothing is telling the system that myComputerName is the machine located at the IP address.
You can either add an entry to your hosts file or to a local DNS server if one is used. If adding to your hosts file (it'll be somewhere like C:\Windows\System32\drivers\etc) and you'll need run your text editor as an Administrator. The entry will look something like this:
192.168.1.1 JSCWorkstation
(obviously change the IP and computer name to your actual values. If the database is running on the same machine as the application you can use the local loopback address (127.0.0.1) as the IP for the entry.
If you are in an environment with a local DNS server you can ask an administrator to add a similar entry in the DNS server.
Once this is done your machine can be found by name rather than by IP address. You can test by opening up a command prompt and typing
ping myComputername. If you get a reply, all is well.