Cannot connect to mysql server with remote access - mysql

My mysql server is installed in Ubuntu 16.04
I used mysql -h 192.168.1.3 -u username -p then following error shows
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.3'
(10061)
I tried to comment the bind-address, it didn't worked.
Thanks in Advance

192.168.1.3 is local ip address, you might not be connected to same network. You need to access it through public ip address. You might also need to create one user and grant permission to that user to access it from outside.

This worked for me:
Out of the box, MySQL will only allow access from the localhost address 127.0.0.1. To change this, you need to open the /etc/mysql/mysql.conf.d/mysqld.cnf file and change the line:
bind-address = 127.0.0.1
to:
bind-address = 0.0.0.0
Save and close that file. Restart the MySQL server with the command:
systemctl restart mysql.service
here is the source : solution

Related

ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115)

I'm trying to make a MySQL database on my Raspberry Pi 4, but it isn't going very well, using localhost instead works perfectly but I want to remote control it from my Windows 10 computer on the same internet. When I create a user with the address of 192.168.1.15 by doing this:
sudo mysql -u root
CREATE USER 'lasse'#'192.168.1.15' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'lasse'#'192.168.1.15';
FLUSH PRIVILEGES
exit
I try to login again using this:
mysql -u lasse -h 192.168.1.15 -ppassword // didnt work, error: ERROR 2002 (HY000): Can't connect to MySQL server on '192.168.1.15' (115)
mysql -u user -h 192.168.1.2 -P 3306 -ppassword // didnt work either, same error.
I have these packages installed:
mariadb-client
mariadb-server
default-mysql-server
In the file /etc/mysql/mariadb.conf.d/50-server.cnf (Raspi-os 2021-03-04 with MariaDB installed), you should replace the line "bind-address = 127.0.0.1" (localhost) by "bind-address = 0.0.0.0" (all). After, you should restart your MySQL server : $ sudo service mariadb restart
Error 115 is returned from socket operation (EINPROGRESS), which means that your client can't physically connect to the specified server and port.
The MariaDB database server is not configured correctly, since it doesn't accept remote connections. Please login locally and check the following variables:
SHOW VARIABLES LIKE 'skip_networking' (result should be off)
SHOW VARIABLES LIKE 'bind-address' (should not be 127.0.0.1)
Since these are read only variables, you need to change them (or comment them out with a #) in your my.cnf configuration file.
ERROR 2002 is "Can't connect" error. Check out /etc/my.cnf, look for listen line. It may be listening localhost or 127.0.0.1. You need to change it to listen 0.0.0.0.
There are three things
You need to set the bind-address to 0.0.0.0 (or 192.168.1.15 to be exact and specific)
You might need to set the firewall to allow port 3306 ( or iptables --flush as shortcut )
You need to create a global user (root#'%') in the mysql database or some user like 'root#192.168.1.15' with a password
when all conditions are fulfilled, you should be able to connect to mysql database on 192.168.1.15
What is most likely the case is that the server is not listening on port 3306. As in both lines you implicit or explicit use port 3306. As it is the only constant in the two lines most likely the culprit.
The default port for clients is specified in my.ini in the [client] section, the port used by the server is in the [mysqld] section. They don't necessarily have be the same so check both.
To make absolutely sure what is going on the server — assuming it is linux — use this to list all listening ports:
sudo netstat -tnlp
There, saved you a walk to the docs.
Login to the MariaDb server and edit the file /etc/mysql/my.cnf
Edit the row bind-address=YOUR_SERVER_IP
Restart the server using '/etc/init.d/mariadb restart' or 'systemctl restart mariadb.service'

How to connect to WSL mysql from Host Windows

I am trying to connect HeidiSql from the host to my WSL Mysql but I could not get it to connect it
Error "can't connect to Mysql server on '127.0.0.1'"
Tried SSH too but could not connect to the server
I'm also hosting mysql-server on WSL and running MySQL workbench on Windows.
I had to get the IP inside of WSL
And use this IP in MySQL Workbench
By default, MySql only listens on 127.0.0.1. If you are connecting using the IP address returned by wsl hostname -I (as mentioned by Permana) then you need to change /etc/mysql/mysql.conf.d/mysqld.cnf to listen on all IPs or your specific IP.
Edit your MySql config by typing this in your Ubuntu instance:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change the line:
bind-address = 127.0.0.1
To:
bind-address = 0.0.0.0
or change 0.0.0.0 to the IP returned by wsl hostname -I.
Restart MySql using: sudo service mysql restart
Since your question is asked before WSL2 release, I assume you were using WSL1.
For WSL1
You can access WSL1 MySQL directly from Windows, but you were attempting access in a wrong way.
In the Network type, you should choose MariaDb or MySQL(TCP/IP) instead of MySQL (SSH Tunnel).
For WSL2
Check this WSL github issue. Save #edwindijas's powershell script and execute it by administrator. If you still cannot access MySQL and got access denied for user ... <you-computer-name>.mshome.net, you need to allow this user access from this host.
For example: let's say root, you need execute this in mysql cli:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%<you-computer-name>.mshome.net' IDENTIFIED BY '<password>';
Or allow root user access WSL2 MySQL from any host:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password';
As for me who's also using WSL for making web based application
first make sure mysql is running on WSL like sudo service mysql start
then once started, open HeidiSql and simply connect to it, here the example on my part
make sure the IP address is 127.0.0.1 not any IP, not your IP used to connect on the internet

Problems connecting to MySQL - Error 2003 (HY000)

Problem:
Using mysql -u -h -p I can connect with localhost but cannot connect with external IP
I check connection for both localhost and external IP where MySQL is installed
What I have set up:
user with host as % (accepts everything)
granted user with host as % (all privileges)
flushed privileges
restarted mysql
checked tablesip and ufw
Any help would be appreciated :) 3 days and counting.
Comment the bind address 127.0.0.1 in mysql configuration file on your remote server.
Generally the file is located at /etc/mysql/my.cnf
on ubuntu system.
EDIT: Restart MySql after done.
Success! Oh my gosh.. there we're two bind address I had to comment out!!
So what I did:
netstat -l Checks to see what IP MySQL is listening to
Checked my.cnf and other linked cnf files
Commented out second bind-address
Done!

Can't connect remotely to MySQL Server with MySQL Workbench

Every time when I'm trying to connect remote mysql server through workbench. It gives me an error
can't connect mysql on remote server '10061'
But I am able to connect with phpmyadmin.
MySQL on default only listens to localhost as a security precaution. You might need to make sure MySQL is listening on your external IP interface:
Follow the steps:
nano /etc/mysql/my.cnf
Edit the MySQL configuration file on your server and go to the following line:
bind-address = 127.0.0.1
The IP address 127.0.0.1 means your MySQL is only listening localhost. Change it to
bind-address = 0.0.0.0
Now MySQL will listen all IP Address.
Add following lines to my.cnf in mysqld section
bind-address = 0.0.0.0
Restart mysql service
Fire following query(on machine to which you want to connect)
i. create new user and password and grand privileges to that IP
GRANT ALL ON database_name.* TO u_name#'202.54.10.20' IDENTIFIED BY 'PASSWORD';
ii. To overwrite privilege
FLUSH PRIVILEGES

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.