Remote Connect to MySQL Database on Ubuntu 20.04 on AWS - mysql

I'm trying to connect to my MySQL database remotely; I feel like I've tried literally everything except for something that feels basic and elusive.
I have my server up as per these instructions:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04
https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql
I've installed this AMI: https://aws.amazon.com/marketplace/pp/prodview-iftkyuwv2sjxi
I've also added security groups (and, yes, I know that SSH shouldn't be open to everyone, I'm just testing)
When I run nc -vz {{MY EC2 IP}} 3306 in my local terminal, nothing happens
When I run nc -vz {{MY EC2 IP}} 3306 my local terminal, I get Connection to {{MY EC2 IP}} 80 port [tcp/http] succeeded!
I've edited my MySQL configuration file via sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf: and made the following changes,
bind-address = 0.0.0.0
I've also run: sudo ufw allow 3306 & tried toggle on/off ufw (but for some reason I feel like I remember that ufw isn't necessary on EC2.
When I run sudo systemctl status mysql, I get:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-02-08 18:41:08 UTC; 19min ago
When I run this it keeps blinking: mysql -u {{user}} -h {{MY EC2 IP}} -p
What am i doing wrong? What am I missing?

Welp, turns out it was 'simple' I just had the wrong security group applied to my instance.
Probably just goes to show that having nice, tidy, & clear Security Group names + cleaning up old ones can save a ton of time.

Related

Cannot connect to MySQL installed on GCP Virtual Machine

I've installed MySQL on a Google Cloud Virtual Machine (debian buster). What I want to do is to make this accessible publicly (using username / password obviously).
As far as I can tell the server is visible from the outside world, as I can ping the IP and I get results, and I think I've set up a user correctly and given the appropriate permissions so I can log in.
For info, my firewall settings on GCP look like this (this is just the egress, there is one exactly the same for ingress):
Which I'm assuming is correct and leaves the correct port open?
The issue I have when I use MySQL Workbench is that when I try to create a new connection, it gives me the following error:
Your connection attempt failed for user 'username' to the MySQL server at [my ip address]:3306:
Unable to connect to localhost
Please:
1 Check that MySQL is running on address [my ip address]
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user username has rights to connect to [my ip address] from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for [my ip address] connecting from the host address you're connecting from**
Any pointers would be gratefully received.
Update: What is really confusing me is the 'Unable to connect to localhost' error. I'm not trying to connect to localhost...?
Update 2: As per comments, results of the following commands:
Note I am trying to connect using the matprichardson username. The svc2toria user is pointing to my own IP address.
Mat, If you want to use your Google Cloud Instance Database using your MySQL workbench. I suggest you connect to it through an SSH tunnel. So, this problem won't happen. I also ran into this problem several times. Connecting through SSH made the job done.
But if your need is something else, this would not help you at all. If your only purpose is managing your database from your local machine using the MySQL workbench. This will work nicely. Create a USER in your Debian VM. and open port 22 to the public. Also, make sure to have strong credentials or a better key file when connecting through SSH. This method is working for every cloud VM database. I'm using this method for G-Cloud, Azure, and AWS. After all of your work is done. Close port 22 (SSH).
My best guess will be because of number 2. "Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)".
Your Virtual Machine will have network security controls / firewall which will be blocking port 3306 by default.
I don't use Google cloud but I believe you are looking for "network details" -> "Firewall rules".
did you change your mysqld.cnf already?
bind-address = 0.0.0.0
As none of the suggestions posted worked I went for the rather more nuclear option of deleting and rebuilding my VM and setting MySQL up again from scratch. I must have done something wrong in my initial setup, as things worked without any issues at all once I’d done this.
The location of the MySQL configuration file differs depending on the distribution.
In Ubuntu and Debian the file is located at /etc/mysql/mysql.conf.d/mysqld.cnf
while in Red Hat based distributions such as CentOS, the file is located at /etc/my.cnf
Open the file with your text editor :
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for a line that begins with bind-address and set its value to the IP address on which a MySQL server should listen.
By default, the value is set to 127.0.0.1 (listens only in localhost).
In this example, we’ll set the MySQL server to listen on all IPv4 interfaces by changing the value to 0.0.0.0
bind-address = 0.0.0.0
# skip-networking
If there is a line containing skip-networking, delete it or comment it out by adding # at the beginning of the line.
In MySQL 8.0 and higher, the bind-address directive may not be present. In this case, add it under the [mysqld] section.
Once done, restart the MySQL service for changes to take effect. Only root or users with sudo privileges can restart services.
To restart the MySQL service on Debian or Ubuntu, type:
sudo systemctl restart mysql
On RedHat based distributions like CentOS to restart the service run:
sudo systemctl restart mysqld
For more Detail Read Here

Failed to start MySQL Database XAMPP

I'm trying to run mysql database server on xampp but the status doesn't change . I've tried all the solutions that i found on the internet but it didn't solve my problem .
Any recommendations ?
If mysql is not starting in xampp, it might be a port conflict issue. Mysql run by default on port 3306. you need to check if another application is occupying that port.
use following command to check app occupying a port
Linux: netstat -tulpn
Window: netstat -a -b
if you find an application occupying that port, stop the application and restart xampp.
As an alternative, you can go to php.ini file or click configure in the dropdown shown in the image and change the mysql port to 3307

Ubuntu + MySQL remote connections

I run two servers one being a web hosting and one being a VPS. I want to use my MySQL server on my web hosting and done everything possible but it still will not work. I started by running the mysql command to grant privileges and it showed that the command went through fine although I still got a refused connection on my web server. I then got told to comment out bind_address in the config but once again it failed.
How can I go about fixing this?
Thanks.
You have to allow mysql to accept requests from remote not only localhost.
To do that you should edit /etc/mysql/mysql.conf.d/mysqld.cnf and change from:
bind-address = 127.0.0.1
to:
bind-address = 0.0.0.0
and restart the mysql server with this command: systemctl restart mysql.service

No able to connect remote mysql database

I'm trying to connect on my mysql database when I'm not on localhost - on localhost it's working. Everytime I wish to connect, I don't have any error, but only a timeout exec...
Here is what I've done so far
create a user on mysql who can access to any hosts("%")
purge the iptables
my port 3306 is opened (see screenshot)
the bind-address line is 0.0.0.0 in the mysqld.cnf file - I even tried to put in it comment - please note my.cnf sends to the mysqld.cnf file.
of course for every modification I've restarted the mysql server - and the server itself...
no firewall are setup...
I'm on Ubuntu 16.04 LTS, mysql and phpmyadmin are setup on it.
What I'm missing ?
Thank you for your help
Bastien
After you changed the bind address you restarted with systemctl restart mysql.service, yes?
Here's a very similar situation, try following all of these steps: Remote Connections Mysql Ubuntu
I think the flush privileges step will be a help to you.

Unable to connect remotely to MySQL Database

I'm currently trying to setup a remote connection to a mysql database. I've done this before, and wrote down some steps to follow for next time, but I can't seem to get this one working. Here's the process I've taken so far.
For the purposes of this question, we'll say that my DB is at ip 100.100.100.100 and the remote host I'm trying to connect from is 100.100.100.200.
Ubuntu Server using Mac OSX terminal:
MySQL is installed, and I've logged in as the root
I've edited my /etc/mysql/my.cnf file to look like this
bind-address = 100.100.100.100
there is no --skip-networking field in my file
Restart mysql
create a new user and grant privileges
CREATE USER 'user1'#100.100.100.200
GRANT ALL ON . to 'user1'
then I update the iptables
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
after all this is finished, I log out of mysql, and try to connect from the remote server with the new user
while on ip 100.100.100.200
mysql -h100.100.100.100 -uuser1
and I get this error message
ERROR 2003 (HY000): Can't connect to MySQL server on '100.100.100.100' (110)
is there something I've missed in the process, or could it be something with the servers firewall? I've been scouring the internet for hours trying to figure this out, so the next step was to ask a question. Thanks in advance for any help you can give!
Man that was a pain.
The problem was in the iptables. I simply restarted the server and re-ran the iptable command.
Restarting the server clears all the iptable rules unless they have been explicitly saved.
Here's the resource I used to find out more about iptables.
https://www.digitalocean.com/community/articles/how-to-set-up-a-firewall-using-ip-tables-on-ubuntu-12-04
sudo reboot - restart the server
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT - add rule to iptables
Not sure what was going wrong, but after a restart and a reinsert of the rule, everything worked like a charm.