GCE and Debian - Unable to connect to MYSQL from TOAD - mysql

In Google Compute Engine, LAMP installed using 'click to Deploy'. I have enabled ALLOW HTTP,HTTPS traffic also in the API console.
I couldn't connect MySQL via Toad. I tried the following Connection Type 1.SSH, 2.TCP, 3.SSL.
Refer this image:
.
I got issues while connecting through any of these three connection types. How to connect MySQL(created using GCE) via Toad?
I used SSH keys also, is there any specific method to connect to this mySQL created via GCE?
My remote server my.cnf file

If you want to connect to Mysql from a remote PC with Toad:
1) Add a firewall rule in the Developer Console Compute Engine network page to allow tcp:3306 (mysql port) to your IP or to everyone (0.0.0.0/0, easier but not secure) and then use Toad TCP connection.
2) Check that mysql user accepts connections from your IP or from every IP (%) or create a new mysql user. You can connect to instance in SSH and give the following commands to create a new Mysql user:
mysql -u root -p
then create user (change 'newuser' and 'password' according to your needs) :
CREATE USER 'newuser'#'%' IDENTIFIED BY 'password';
Grant user permission:
GRANT ALL PRIVILEGES ON * . * TO 'newuser'#'%';
FLUSH PRIVILEGES;
exit;
If connection still fails:
3) Check that mysql is listening on all IP addresses, for Debian see in /etc/mysql/my.cnf and change bind-address to :
bind-address = 0.0.0.0
and restart mysql:
/etc/init.d/mysql restart
Hope this helps.
Sincerely,
Paolo

Id try to access mysql from another server in the same network and project to help narrow down where your requests are getting blocked. If you can access mysql from another instance then it could be your firewall rules.
Also, does debian have iptables or another software firewall enabled by default?

Related

How to connect to MySQL instance on Google Compute Engine via Apps Script JDBC?

I've successfully connected to a Google Cloud MySQL instance using GAS and JDBC. As a sanity check, I also connected to a MySQL instance on a free hosting site. Despite these successful connections, I can't seem to do this with a MySQL instance on Google Compute Engine using the following command:
var conn = Jdbc.getConnection("jdbc:mysql://11.111.111.111:3306/myDBName",user,pwd),
where 11.111.111.111 is the external IP address that I retrieved from the Google Cloud Platform page for my VM instance.
Note that I've mainly worked with local instances of databases so I might be missing something obvious here. I'm wondering if I don't understand something about how to use the server? Am I supposed to use an IP address other than the external IP provided by Google? Below are the things that I've thought through to try to solve this.
Establish MySQL user
Here's how I setup the user in MySQL:
CREATE USER 'user'#'localhost' IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON * . * TO 'user'#'localhost';
FLUSH PRIVILEGES;
When that didn't work, I tried:
CREATE USER 'user'#'%' IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON * . * TO 'user'#'%';
FLUSH PRIVILEGES;
I did double-check that I can login via the command line using the user/pwd credentials.
MySQL install
I used Google's instructions for how to install MySQL on Compute Engine (Ubuntu).
I double-checked that I'm using MySQL 5.7 since it seems up to 5.7 is supported by GAS JDBC.
mysql --version returns mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64).
Port
I used sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf to check the port, and it is 3306. I also enabled port forwarding on my VM instance.
config file
In mysqld.cnf, I changed
bind-address = 127.0.0.1 to bind-address = 0.0.0.0. There was no line for skip-networking to comment out. After making edits, I restarted the service using sudo systemctl restart mysql.
IP addresses
When I look in the firewall section for my VM, I only see two filtered IP addresses: 10.128.0.0/9 and 0.0.0.0/0.
Also, I tried sudo ufw allow 3306, which didn't help me connect either.
I know that Google says to whitelist IP addresses but the instructions that they give for external databases are actually for Cloud SQL. I'm not sure what to do with that info or if it's necessary since I was able to connect to other databases all under the same Google account.

Access Denied for User 'username'#'IP' error - digtal ocean

I've currently set up a staging area for my app in Digital Ocean with LAMP stack. The Framework for my app is Laravel 5.5 and Vue 2x.
In development, I've been using remote MySQL and had no issues with the connection error. However, when I moved it to the staging env, it is giving me access denied error. When I looked at it closely to the error log, Access denied is for username#[digital-ocean-droplet-ip], whereas I have properly configured the MySQL credentials to the remote host IP under laravel's config/database file.
So, I am doubtful if I have to do any configuration under Apache to allow any external MySQL connection? I forgot the cmd but I did allow sfw firewall allow to any port 3306 to the remote server IP address in Apache.
Any help is appreciated.
Thanks!
MySQL by default does not create an user with access from remote connections.
First you need to create an user on database that allows connection from outside (%) or a specific IP
CREATE USER 'newuser'#'%' IDENTIFIED BY 'password';
Than give him privileges
GRANT ALL PRIVILEGES ON *.* TO 'newuser'#'%';
The *s could be replaced by your database and table name respectively
You might also check if in your mysql configuration(/etc/mysql/mysql.conf.d/mysqld.cnf in my case) has this line uncommented
bind-address = 127.0.0.1
Change the ip if necessary
restart mysql and apache
sudo service apache2 restart
sudo service mysql restart
Than update the user and password at your .env file and try again!

MySQL unable to connect with remote server

We have a MySQL server in one of the remote Virtual Machine (Windows Server 2008). Till yesterday we were able to connect to the MySQL server, with the help of workbench installed in our local machine.
Yesterday there was a restart to the machine which has the Virtual Machine installed. After that we are unable to connect to MYSQL. Though I can ping and remote connect this particular VM. I can even execute the queries inside the workbench installed in the VM.
I am not too good at networking or security related stuffs. Please help me to solve this issue.
Error :
Your connection attempt failed for user 'root' from your host to server at ABC:3306: Can't connect to MySQL server on 'ABC' (10060)
Really this could be a magnitude of possible reasons, hopefully this is a start:
Check basic network
From the MySQL virtual machine open up a command prompt and type IPCONFIG /ALL. This will show you all the IP addresses bound to different network adapters.
Check that the IP address you're connected to is listed there, the virtual machine might have got a new IP from DHCP rather than having a static IP after its restart.
Hostname vs IP
You should check the hostname resolution, from your quoted error it would suggest you are you are connecting to a hostname rather than a server IP. Check your machine can resolve to the hostname using the correct IP address - it could also be worth changing the hostname for the actual IP of the server in the connection string.
MySQL config file
You've said you're running MySQL on Windows, it was customary to rename the my.cnf to my.ini. The configuration file for older versions of MySQL previous to 4.1.5 was usually stored in either c:\my.ini or c:\windows\my.ini. For versions after this the default location is the installation directory usually %PROGRAMDATA%\MySQL\MySQL Server xxx.
When you have located the configuration file please open it on Notepad (or similar text editor), locate the [mysqld] section and make sure that port= the port you're trying to connect to and bind-address= the IP address you're trying to connect to.
Server ports
From the MySQL virtual server open a command prompt and type netstat –ano, this will show you a list of processes and what IP's / ports they are listening on. The MySQL server should be listed here and should be listening on the same port and IP as the config file defines.
Windows firewall
You should have a firewall rule to allow MySQL, the following will add one on the default port of 3306
netsh advfirewall firewall add rule name="MySQL Server" action=allow protocol=TCP dir=in localport=3306
Identify if this is machine specific
You could setup the MySQL Workbench application on another workstation and try to connect to identify if this is a global problem or just one related to your specific workstation.
mysql administrator of your database should allow remote connection to the mysql server.
change this in my.cnf:
bind-address = 127.0.0.1 # this shoul be your mysql server ip
and comment this:
# skip-networking
Chances are that your configuration was set up for an IP that has changed. By default, mysql won't let you connect from remote hosts unless you explicitly give permissions for a specific user on a specific schema or a group of schemas, for example if you did something like this:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Maybe what you actually did was to set the grant onto your own IP address, that is the address of your local machine, and if your local machine (not the remote server) has changed it's IP address, then mysql will not let you connect unless you have the "1.2.3.4" IP address which obviously you don't have anymore if you have a dynamic IP address (common with DSL/Cable connections)
So connect through SSH or Telnet or whatever you use to your windows server and go to mysql as root and do this:
SELECT * from information_schema.user_privileges;
That will show you the grants on all users and how they are allowed to connect. If you don't see your local IP Address listed there or a wildcard (which would allow you to connect from any remote machine to the server) then you have to set it up like this:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Where USERNAME of course is your user. See that after the on there is a wildcard / dot /wildcard that means you want that user to be able to connect to any schema (database, for mysql) from any user from any network. But I'd recommend that you only do the grant for the user for the specific schema you need to connect to.
Then after that, if you actually had the right information and still can't connect than use a portscanner like nmap or something like that to do a port scan and see if mysql is:
Open and listening to external network
Running on the port that you actually want to connect through
If 1 is true, then check 2 because maybe there is a misconfiguration of the port. But if any of these 2 points do work then it sounds definitely not like a network configuration but a user setting or something else.
GRANT ALL ON *.* to user#'%' IDENTIFIED BY 'password';
this command should do the trick for all users #Gustavo Rubio has already given the proper explanation.
To ensure what ports are open run cmd in the virtual machine and type.
netstat -a
TCP 127.0.0.1:3360 Hostname:3360 LISTENING
The my.cnf is located Mysql-install-path\MySQL\MySQL Server xxx make sure you backup original before changing
Can't connect to [local] MySQL server
Testing The MySQL Server Installation on Microsoft Windows
MySQL Workbench: Manage MySQL on Windows Servers the Windows way
For the first time you need to test and make sure your connection to mysql is not blocked by the firewall.
To disable the firewall on each host in your cluster, perform the following steps on each host.
1. Save the existing iptables rule set.
iptables-save > /root/firewall.rules
2. Disable iptables.
For RHEL, CentOS, Oracle, and Debian:
chkconfig iptables off
and
/etc/init.d/iptables stop
For SLES:
chkconfig SuSEfirewall2_setup off
and
rcSuSEfirewall2 stop
For Ubuntu:
service ufw stop
https://www.cloudera.com/documentation/enterprise/5-7-x/topics/install_cdh_disable_iptables.html
Depends on your setup, but if you're using cPanel just go to RemoteMYSQL and enter your host. You can also use a wildcard. Below worked for me when I was getting the error
"Could not connect to DB server '' as user ''. port : Host '' is not
allowed to connect to this MySQL server"
On MySQL v5.6 this may be the case.
When another server communicate by advertising its hostname instead of IP address, the resolution might fails (because your user is using IP address instead of hostname for example).
So, you need to disable the following,
skip-host-cache
skip-name-resolve
Or maybe create the user with appropriate hostname (instead of IP address). You may find the hostname when establishing the connection to the remote MySQL.

How to access MySQL from a remote computer (not localhost)?

I have my dev environment set up as a Ubuntu Server (with LAMP installation) inside a vmware. The vmware is running on my local windows 7 machine. When I try to access my mysql server via HeidiSQL program the connection fails. I get a:
Server Error 2003, can't connect to mysql server on <IP ADRESS HERE>
I can however access the db server via PhpMyAdmin. MySQL is running and my connection credentials and port are all correct.
I read that you should enter the IPs of the computer you are trying to connect from as the "bind address" in the my.cnf file. Which I did. I tried both the internal network IP as well as the online IP. Still no luck, same message.
Since this isn't a production environment I would ideally like to allow anyone to access that server, not limit it by IP. Especially since my ISP assigns dynamic IPS. So I would have to change it all the time, assuming that even works.
So does anyone know how I can connect to my MySQL server from a remote computer?
P.S. I assume this is something developers have to deal with that's why I posted it here and not Super User. If it must be migrated please send it to Server Fault not Super User.
Ok, be aware this gives the world and his dog access to your mysql server.
GRANT ALL ON *.* to '%'#'%' WITH GRANT OPTION;
But say you are on your home network of 192.168.1.2/16 then you can at least limit it like this.
GRANT ALL ON *.* to '%'#'192.168.%' WITH GRANT OPTION;
Another option is that you have a user and password but want to connect from anywhere
GRANT ALL ON *.* to 'mysecretuser'#'%' IDENTIFIED BY 'mysecretpassword' WITH GRANT OPTION;
first check the ip assigned to vmware using from cmd
ipconfig/all
suppose ipassigned to vmware is 192.168.11.1
now in vmware in ubuntu check the ipadress
ifconfig
suppose ip adress of ubuntu is 192.168.11.137
now open mysql configurations
sudo nano /etc/mysql/my.cnf
change the bind address to ubuntu ip address
bind-address = 192.168.11.137
restart mysql
now connect to mysql
mysql -u root -p
and create a user with all privileges and host ip of vmware i.e 192.168.11.1
GRANT ALL ON db.* TO user#'192.168.11.1' IDENTIFIED BY 'PASSWORD';
now try to connect from windows.
also open port of mysql
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
restart mysql and try to connect on ubuntu host ip address 192.168.11.137
For Heidi SQL I was able to get it to work following the instructions on this article:
http://mysql-tools.com/en/articles/http-tunnel/73-heidisql-a-http-tunnel.html
It uses a program called HTTP Tunnel. It's a lot slower but at least it works. If you use Navicat it comes with a PHP file that you can upload to your server and it will connect via that.

cant access remote mysql server need help

I have a unix server with mysql which I am trying to access from my machine. To clarify, access the mysql server. When I do I get this error.
Connecting to MySQL server 192.168.1.25...
Can't connect to MySQL server on '192.168.1.25' (10061)
Here are my credentials:
username: root
port: 3306
The server is running because I am able to remotely login onto the machine (with ip: 192.168.1.25" and then run mysql from root. What do you think is going on:
Is it a firewall issue?
Accessing as 'root' is being denied?
I am new to mysql.
1)
check the logs
you can see where the logs are by checking the my.cnf file.
mysqld.log might be the file name, but where
2)
a. see if it's a network issue.
telnet 192.168.1.25 3306
b. see if the service is at that port.
ssh to the box
# from the local host
mysql -u root
telnet 127.0.0.1 3306
ps auxw|grep mysql
you should hopefully have enough diagnostic info at this point to figure it out.
Probably because remote root login is not allowed. You can try this article on how to enable remote root:
http://benrobb.com/2007/01/15/howto-remote-root-access-to-mysql/
i have this problem and fix it by
first you must grant all to user
GRANT ALL PRIVILEGES ON databasename. TO 'user'#'%' IDENTIFIED BY 'password';
then
FLUSH PRIVILEGES;
and change the mysql config using
sudo nano /etc/mysql/my.cnf
find "bind-address" row and comment it.
save config and restart mysql using
sudo /etc/init.d/mysql restart
hope solve problem :)
The Message (10061) is do to offline severs or firewall blockage
If you get -the name of your pc - can not connect, then mysql is rejecting the connection and you will have to create a 'user' in the mysql database mysql, table user using the IP of the remote connection', and restart the database service
but for error 10061 check The Firewall in both machines.
Masters PC per say, is the one with the phpmyadmin installation
Allow Destination ip-[the remote] and port 3306 on the Master Machine
and
Allow source ip-[the masters]/with any port, and check your destination port(3306) too. destination ip can also be set on some firewalls.
And if you can, search in your firewall for logs, settings, recent activity, etc... to see what and how you are being blocked.