Cannot connect remotely to MySQL (TCP/IP) running on Windows - mysql

I'm trying to connect to MySQL Server installed on a machine with Windows OS. The connection is remote to type, but not on a local network (LAN). A pc (also with windows) in my house and the other in college. For three days I have been reading the documentation on the MySQL website and other sources, such as other SO questions but got no success. Below all my settings. Also wanted to know if anyone else is having the same problem. No need to mention the issue of security (SSH, token, pipe, etc), I do this using free software just to show the lack of security or bad pratice, just to educational purposes.
All ports are open on the router, and it is configured correctly, firewall off;
Firewall turned off on both computers (client / provider) and all the doors open;
The two computers have Win7 Ultimate 64x;
The service of MySQL 5.5.37 Community Server is running on the server computer;
The client tries to connect by HeidiSQL 8.3 (TCP/IP) (64x);
The SQL GRANT ALL PRIVILEGES ON * TO 'USERNAME' # 'IP' IDENTIFIED BY 'PASSWORD';. FLUSH PRIVILEGES;, has already been tested.
The file "my.ini" was checked the "bind-address" in the Win version does not have this entry.
The variable "skip_external_locking" was set to "OFF";
Services such as FTP and HTTP function normally.
Any tips on this question were tested.
Misses something important?
The error:
ERROR 2003 (HY000): Can't connect to MySQL server on 123.123.123.123 (10061)
mysql> select host,user,password from mysql.user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| % | root | *blablablablabla |
| 127.0.0.1 | root | *balblablalbalbalb |
| ::1 | root | |
| localhost | | |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)

I finally got it! So what I did:
Fully Uninstall MySQL;
I installed the latest version of MySQL 5.6;
I did all the steps in the question above;
I did all the tests of ports, and everything working;
I tried to connect as root to the host '%', it did not work;
I created a new User with all privileges of the root and host '%', then I could connect.
When did MySQL 5, all the doors were open and still not connected, even putting exceptions in the firewall for the ports and for the mysql program. But when I installed MySQL 6 it automatically created the exception to the windows firewall as below:
Were equal to MySQL5.This was not an answer. In fact Windows the best way to prevent such inconvenience is always using the latest version of MySQL. So if someone did all the steps I listed in the question and did not work, completely uninstall MySQL and install the latest version may solve the problem, just be careful with your database.

Related

How to connect to a docker container database on a remote ubuntu server?

I've tried searching left and right and I can't find a solution to my problem. I can connect perfectly fine on my localhost to my docker container's database (simply by connecting to localhost/127.0.0.1/ubuntuip) on dbeaver, but when it comes to connecting to my docker mysql container on the remote ubuntu server (so not the ubuntu running on my computer), it doesn't work.
Things I've tried
Connecting to the ubuntu server ip (by doing "hostname -I";
Connecting to the ip shown when I run "curl http://checkip.amazonaws.com" on the remote ubuntu server (I ssh into it);
Connecting to the docker container ip when I do inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id on the remote ubuntu server.
None of those worked and I'm getting a bit lost honestly. When I do select host, user from mysql.user on the remote ubuntu server, I get this :
mysql> select host, user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
From what I understand, I should be able to connect to it since I allow any host (this is dev, not prod). I can easily ping my db container, the tables are created fine in it and everything. I just can't connect to it from my Dbeaver.
Any help is appreciated, thanks :)
Fixed it. Just like David Maze said, I had to connect to the same url as the one I used to ssh, but I had already tried that. What I had to do was to also go in the SSH tab on dbeaver and add the host (same url) and select the auth method to "public key" and I selected my ssh key folder (id_rsa) which is located at \\wsl$\Ubuntu-18.04\home\user\.ssh\id_rsa. I left the "passphrase" blank and now it works!
Thanks for the help!

Remote acess to MySql 5.7 does not working

Hi guys I have a situation where I need that my Web Application, hosted in some other machine, access my local MySql Server Instance. My string connection looks like
mysql://<user>:<password>#<my_ip>:3306/<data_base_name>
However when I try to connect I am getting the error:
Can't connect to MySQL server on '1**.***.**.*7' (111)
Searching a little bit I discovered that it could be due the configuration of bind-address in my.conf file. However in MySql 5.7 there is no need to do that once, when I run the select below I get this:
show variables like 'bind%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| bind_address | * |
+---------------+-------+
Searching a little bit more, I found that it could be due the firewall blocking connection on port 3306. Then I created an inbound and outbound rule for that, but I'm still getting this error and I can perfectly connect to my MySql Server locally.
Besides, I've already seen these posts:
Can't connect to MySQL server error 111
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
How to allow remote connection to mysql
https://serverfault.com/questions/823877/mysql-connection-not-working-with-windows-firewall-on
However none of them solved my problem. Someone can help me out?

XAMPP MySQL and phpMyAdmin have different databases

I am new in XAMPP MySQL and PHPMyAdmin. The databases on these two platforms should be the same. However, similar to the problems shown in MySQL and PHPMyAdmin matching problem,
I found that SELECT ##hostname have the same results on XAMPP MySQL and PHPMyAdmin. However, the result for running SHOW databases on XAMPP MySQL is
*
information_schema |
mysql |
people |
performance_schema |
phpmyadmin |
test
*
whereas the result for running SHOW databases on PHPMyAdmin is
*
information_schema |
test
*
By the way, I am running XAMPP MySQL on Windows 10 PowerShell. Comments and ideas are appreciated.
Probably when you're connecting through phpMyAdmin, you're authenticating to MySQL as the anonymous user. Most MySQL installations come with an anonymous user which doesn't have many privileges at all, but can connect and see the databases you reference.
This could be because you're using a different username and password, or because the two methods are using a different connection type — to MySQL, a connection to over TCP/IP networking authenticates as a user with host "%" (or a specific IP address). A socket connection authenticates to the "localhost" host. Using host names of 127.0.0.1 (or any IP address/hostname) forces a TCP/IP connection; connecting to 'localhost' forces a socket connection.
So probably what's happening here is that you're using the phpMyAdmin default connection type of localhost and telling the command-line client to connect to 127.0.0.1, but you only have your user set for host '127.0.0.1' (or '%'). You can edit your phpMyAdmin configuration to tell it to connect to 127.0.0.1 instead, or duplicate the user#127.0.0.1 and give the new user the host 'localhost'. Either should get you in again if this is the cause.

Bizarre MySQL Workbench error on Linux desktop

I have an account with a Java PaaS (CloudBees) that hosts their platform off of Amazon EC2 instances. My account comes with access to a MySQL server instance and I am getting a bizarre error that only occurs when I try to log into the MySQL server from a client on my linux (Ubuntu 12.04 desktop) machine, but not my Windows 7 machine.
Here is a screenshot of the error when I try to log in with MySQL Workbench on my Ubuntu machine:
It's important to note that I have another MySQL client (Squirrel SQL) installed on this machine, that throw the same exact error when I try to log in to my dl_web account. Squirrel SQL is a pure Java application, and I have tried to check that MySQL Workbench and Squirrel SQL do not share any common dependencies and couldn't find any (but I could be wrong).
However, when I try to log in with a MySQL Workbench instance living on my Windows 7 machine, I can log in just fine.
Given the list of 4 things to check from that error message:
Yes, of course MySQL server is running on the EC2 instance; otherwise CloudBees would be out of business and I wouldn't be able to log in from my Windows 7 machine.
3306 is the correct port - I verified this with CloudBees support staff.
Not sure about this one - perhaps the MySQL server instance is somehow configured to refuse connections from linux clients?!?!
The password I'm using is correct - I have checked and re-checked and re-re-checked.
So the only 2 theories I have so far are:
The MySQL server instance is somehow configured to refuse connections from Linux clients (is this even possible?); or
The MySQL Workbench and Squirrel SQL instances on my Ubuntu machine are sharing some common dependency that is buggy or misconfigured; this is the more likely of the two scenarios, but I have been unsuccessful pegging down what this dependency is...
Also - note the exact error message that I get from both MySQL Workbench and Squirrel SQL:
Access denied for user 'dl_web'#'%' to database...
My user is dl_web...not 'dl_web'#'%'!!! Bizarre, right?!
Any ideas? Thanks in advance!
You appear to be in a hosted environment within AWS where you do not have access to root or to view grants on tables, but this may help someone else and show a few steps.
first, if I go into sqlyog (or toad or mysql workbench) and try to connect to AWS mysql, i get the following error:
http://img836.imageshack.us/img836/4594/out1.GIF
so the issue is root#pool-72-93-207-216.bstnma.fios.verizon.net
so i get into mysql at root (yes I know you might not be able to do this !)..
and I perform the following
mysql> use test;
mysql> grant all privileges on test.* to 'root'#'pool-72-93-207-216.bstnma.fios.verizon.net' identified by 'mypassword123z';
mysql> select user,host from mysql.user;
+------------------+--------------------------------------------+
| user | host |
+------------------+--------------------------------------------+
| foo_user | % |
| root | 127.0.0.1 |
| foo_user | 72.93.207.216 |
| foo_user2 | 72.93.207.216 |
| root | ::1 |
| | domU-12-31-38-04-B2-89 |
| root | domU-12-31-38-04-B2-89 |
| | localhost |
| debian-sys-maint | localhost |
| phpmyadmin | localhost |
| root | localhost |
| root | pool-72-93-207-216.bstnma.fios.verizon.net |
+------------------+--------------------------------------------+
mysql> SHOW GRANTS FOR 'root'#'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*4F4504C8CA8D22648E58B5092F653457698A9EBE' WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
mysql> show grants for 'root'#'pool-72-93-207-216.bstnma.fios.verizon.net';
+----------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#pool-72-93-207-216.bstnma.fios.verizon.net |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'#'pool-72-93-207-216.bstnma.fios.verizon.net' IDENTIFIED BY PASSWORD '*CACE4BB4D0A5D265BA7FCBEED600DC8976884A43' |
| GRANT ALL PRIVILEGES ON `test`.* TO 'root'#'pool-72-93-207-216.bstnma.fios.verizon.net' |
+----------------------------------------------------------------------------------------------------------------------------------------------+
then I go back to sqlyog (or toad or mysql workbench) and log in with root and password mypassword123z and I am in.
in addition you can create an secure SSH proxy tunnel thru port 22 and your AWS pem file, using like Putty.

Using an alias for the localhost server in MySQL

When I am at the office, MySQL runs on a specific server which is called "mysqldev". In my /etc/hosts file I have set "mysqldev" to match the IP of this server. So far, so good. However, when I am out of the office using my laptop, I want to use my local MySQL database, as I clone specific databases there and have no internet to connect to the office database. I do not want to change my scripts, but rather my laptop configuration. So on my laptop I have set in /etc/hosts:
127.0.0.1 localhost mysqldev
However, for some reason this does not work as expected. If I log in to MySQL using the server at localhost, all good. But when I try to log in on the mysqldev server (same IP as localhost), I get the error:
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] Connection refused (trying to connect via tcp://mysqldev:3306)
(this is using PHP, but using the command line it is the same error)
The users that are set up on the system have specific permission to log in on this server:
CREATE USER 'test'#'mysqldev' IDENTIFIED BY '123';
GRANT ALL PRIVILEGES ON testdb.* TO 'test'#'mysqldev';
I have also turned off the firewall to test, and it does not make a difference. What could it be?
The MySQL client library tries to guess how to connect to your database. When you give localhost as the hostname, it assumes, that you're using a local socket (search your computer for a file named mysql.sock, probably under /var/lib/mysql or /usr/local/mysql/.
However, when you use anything else, like an ip address, a different hostname, or, in your case, mysqldev, it tries to connect to the host via tcp. From the error message, it seems as if your local mysql server is not listening on the tcp port 3306 (the mysql default)
Check, if your my.cnf (probably /etc/my.cnf or /etc/mysql/my.cnf) allows the use of tcp. If you find a line like
skip-networking
comment it out:
#skip-networking
and restart the server. Then try again to connect.
To find out, where your socket is, connect through localhost and issue the following command:
mysql> show global variables like '%socket%';
+---------------+-----------------------------+
| Variable_name | Value |
+---------------+-----------------------------+
| socket | /var/run/mysqld/mysqld.sock |
+---------------+-----------------------------+
If you are using MAMP Pro and are running into issues, you can simple uncheck the box labeled "Allow local access only" within the MySQL Server settings.