Can't connect remotely to MySQL Server with MySQL Workbench - mysql

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

Related

Cyberpanel - how to enable remote sql connection with MYSQL Workbench [duplicate]

I have installed MySQL Community Edition 5.5 on my local machine and I want to allow remote connections so that I can connect from external source.
How can I do that?
That is allowed by default on MySQL.
What is disabled by default is remote root access. If you want to enable that, run this SQL command locally:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
And then find the following line and comment it out in your my.cnf file, which usually lives on /etc/mysql/my.cnf on Unix/OSX systems. In some cases the location for the file is /etc/mysql/mysql.conf.d/mysqld.cnf).
If it's a Windows system, you can find it in the MySQL installation directory, usually something like C:\Program Files\MySQL\MySQL Server 5.5\ and the filename will be my.ini.
Change line
bind-address = 127.0.0.1
to
#bind-address = 127.0.0.1
And restart the MySQL server (Unix/OSX, and Windows) for the changes to take effect.
After doing all of above I still couldn't login as root remotely, but Telnetting to port 3306 confirmed that MySQL was accepting connections.
I started looking at the users in MySQL and noticed there were multiple root users with different passwords.
select user, host, password from mysql.user;
So in MySQL I set all the passwords for root again and I could finally log in remotely as root.
use mysql;
update user set password=PASSWORD('NEWPASSWORD') where User='root';
flush privileges;
Just a note from my experience, you can find configuration file under this path /etc/mysql/mysql.conf.d/mysqld.cnf.
(I struggled for some time to find this path)
In my case I was trying to connect to a remote mysql server on cent OS. After going through a lot of solutions (granting all privileges, removing ip bindings,enabling networking) problem was still not getting solved.
As it turned out, while looking into various solutions,I came across iptables, which made me realize mysql port 3306 was not accepting connections.
Here is a small note on how I checked and resolved this issue.
Checking if port is accepting connections:
telnet (mysql server ip) [portNo]
Adding ip table rule to allow connections on the port:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
Would not recommend this for production environment, but if your iptables are not configured properly, adding the rules might not still solve the issue. In that case following should be done:
service iptables stop
Hope this helps.
All process for remote login. Remote login is off by default.You need to open it manually for all ip..to give access all ip
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password';
Specific Ip
GRANT ALL PRIVILEGES ON *.* TO 'root'#'your_desire_ip' IDENTIFIED BY 'password';
then
flush privileges;
You can check your User Host & Password
SELECT host,user,authentication_string FROM mysql.user;
Now your duty is to change this
bind-address = 127.0.0.1
You can find this on
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
if you not find this on there then try this
sudo nano /etc/mysql/my.cnf
comment in this
#bind-address = 127.0.0.1
Then restart Mysql
sudo service mysql restart
Now enjoy remote login
Please follow the below mentioned steps inorder to set the wildcard remote access for MySQL User.
(1) Open cmd.
(2) navigate to path C:\Program Files\MySQL\MySQL Server 5.X\bin and
run this command.
mysql -u root -p
(3) Enter the root password.
(4) Execute the following command to provide the permission.
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'IP' IDENTIFIED BY
'PASSWORD';
USERNAME: Username you wish to connect to MySQL server.
IP: Public IP address from where you wish to allow access to MySQL
server.
PASSWORD: Password of the username used.
IP can be replaced with % to allow user to connect from any IP
address.
(5) Flush the previleges by following command and exit.
FLUSH PRIVILEGES;
exit;
or \q
I had to this challenge when working on a Java Project with MySQL server as the database.
Here's how I did it:
First, confirm that your MySQL server configuration to allow for remote connections. Use your preferred text editor to open the MySQL server configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Scroll down to the bind-address line and ensure that is either commented out or replaced with 0.0.0.0 (to allow all remote connections) or replaced with Ip-Addresses that you want remote connections from.
Once you make the necessary changes, save and exit the configuration file. Apply the changes made to the MySQL config file by restarting the MySQL service:
sudo systemctl restart mysql
Next, log into the MySQL server console on the server it was installed:
mysql -u root -p
Enter your mysql user password
Check the hosts that the user you want has access to already. In my case the user is root:
SELECT host FROM mysql.user WHERE user = "root";
This gave me this output:
+-----------+
| host |
+-----------+
| localhost |
+-----------+
Next, I ran the command below to grant the root user remote access to the database named my_database:
USE my_database;
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'my-password';
Note: % grants a user remote access from all hosts on a network. You can specify the Ip-Address of the individual hosts that you want to grant the user access from using the command - GRANT ALL PRIVILEGES ON *.* TO 'root'#'Ip-Address' IDENTIFIED BY 'my-password';
Afterwhich I checked the hosts that the user now has access to. In my case the user is root:
SELECT host FROM mysql.user WHERE user = "root";
This gave me this output:
+-----------+
| host |
+-----------+
| % |
| localhost |
+-----------+
Finally, you can try connecting to the MySQL server from another server using the command:
mysql -u username -h mysql-server-ip-address -p
Where u represents user, h represents mysql-server-ip-address and p represents password. So in my case it was:
mysql -u root -h 34.69.261.158 -p
Enter your mysql user password
You should get this output depending on your MySQL server version:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Resources: How to Allow Remote Connections to MySQL
That's all.
I hope this helps
Close comment at link /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/mysql/my.cnf:
bind-address = 127.0.0.1 =>> #bind-address = 127.0.0.1
Change the hostname so that all machines can access it, run this SQL command locally:
UPDATE mysql.user SET Host='%' WHERE Host='localhost' AND User='root';
FLUSH PRIVILEGES;
Restart service:
sudo service mysql restart
Open port mysql:
sudo ufw allow 3306
If your MySQL server process is listening on 127.0.0.1 or ::1 only then you will not be able to connect remotely. If you have a bind-address setting in /etc/my.cnf this might be the source of the problem.
You will also have to add privileges for a non-localhost user as well.
If you installed MySQL from brew it really does only listen on the local interface by default. To fix that you need to edit /usr/local/etc/my.cnf and change the bind-address from 127.0.0.1 to *.
Then run brew services restart mysql.
Just F.Y.I
I pulled my hair out with this problem for hours.. finally I call my hosting provider and found that in my case using a cloud server that in the control panel for 1and1 they have a secondary firewall that you have to clone and add port 3306. Once added I got straight in..
For whom it needs it, check firewall port 3306 is open too, if your firewall service is running.
This blog How to setup a MySQL server on Local Area Network will be useful in setting up a MySQL from scratch
If mysqld has a bind address set to a loopback/local address (e.g. 127.0.0.1), the server will not be reachable from remote hosts, because a loopback interface cannot be reached from any remote host.
Set this option to 0.0.0.0 (:: for IPv4+6) to accept connections from any host, or to another externally-reachable address if you want to only allow connections on one interface.
Source
And for OS X people out there be aware that the bind-address parameter is typically set in the launchd plist and not in the my.ini file. So in my case, I removed <string>--bind-address=127.0.0.1</string> from /Library/LaunchDaemons/homebrew.mxcl.mariadb.plist.
Enabling remote root access can be dangerous. It would be preferable if you were to set up user accounts with more restrictive permissions. The following three steps should do it.
Ensure that the line starting with bind-address ... is at least commented out in your my.ini or my.cnf file. If it doesn't exist, move on.
You can find this file in C:\ProgramData\MySQL\MySQL Server 8.0 on Windows.
Afterwards, check that the user account you are establishing the connection with does not have localhost in the Limit to Hosts Matching field. While it isn't recommended, you can instead put % in that field for testing purposes. You can do this by opening a local connection to the server with MySQL Workbench, then going to Server>Users and Privileges from the menu bar and finding the user account you want to connect with.
The "Limit to Hosts Matching" field is what disallows you to connect non-locally. I.e. it limits the accepted connections to a pattern of IP addresses. Ideally, you should be accessing the MySQL server from a static IP address or subnet, so that you can be as restrictive as possible.
Obviously, your firewall should allow the MySQL Server application to communicate over the port you want. The physical networking equipment in between you and your server should allow communication on the port you want to connect with. (port 3306 typically)
MySQL 8 no longer allows you to create a user using the GRANT command. You need to create the user first.
CREATE USER 'root'#'%' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
some times need to use name of pc on windows
first step) put in config file of mysql:
mysqld.cnf SET bind-address= 0.0.0.0
(to let recibe connections over tcp/ip)
second step) make user in mysql, table users, with name of pc on windows propierties, NOT ip
Check remote server grant permission to Wildcard access to port 3306:
sudo lsof -i -P -n | grep LISTEN
It should NOT be same like this:
mysqld 23083 mysql 21u IPv4 145900142 0t0 TCP
127.0.0.1:3306 (LISTEN)
In this case, we need to update /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf with:
bind-address = 127.0.0.1 --> 0.0.0.0
And then restart mysql "sudo service mysql restart"
In order to test mySQL connection from a client:
nc -vz <host_address> 3306

Connect to Mysql database from remote

Problem:
I have server where is install Laravel app and database. But i want share same database with another server. And i want enable remote access.
What i tried:
I changed config file /etc/mysql/mysql.conf
commented out bind-address = 127.0.0.1
Also changed to bind-address = 0.0.0.0 or bind-address = *, not helps
(this is what everywhere i found to do)
ufw is disabled
netstat -ltn returns
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
isn't 127.0.0.1:3306 suppose to be 0.0.0.1:3306?
I try connect from another server
mysql -h xxx.xxx.xxx.xxx -u pf_remote -p
i got error
Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)
I think that port is not open, but where else i can open. Do i miss something?
Find mysql.conf and set
bind-address=0.0.0.0
Then login to MySQL and run below 2 commands
GRANT ALL PRIVILEGES ON *.* TO 'pf_remote'#'%' IDENTIFIED BY 'your_password' with grant option;
flush privileges;
then
sudo service mysql restart
Then also make sure you do not have any firewall blocking connections, check by
sudo ufw status
If its enabled, then allow remote connections to MySQL port
sudo ufw allow 3306 && sudo ufw reload
If you are using Amazon Web Services server then allowing connections from within shell won't work, you will have to allow connections from AWS Dashboard
Try to grant priviliges to user for remote access:
mysql> GRANT ALL ON yourDatabase.* TO user#'1.2.3.4' IDENTIFIED BY 'yourPassword';
Also please remember to restart your mysql service after config changes:
sudo /etc/init.d/mysql restart

Unable to connect to remote mySQL database which is running on a container on different machine

I am trying to connect to mySQL database on a different machine. And the mysql is running on a container.
I used given bridge network ip address generated for docker container to access mysql from different machine(on same wifi network).
before that i have granted access to host IP address by running below commands in mysql console.
GRANT ALL PRIVILEGES ON *.* TO 'root'#'172.x.x.x' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
also updated /etc/mysql/my.cnf file
bind-address = 127.0.0.1
bind-address = 172.x.x.x
when i tried to execute with mysql -u root -h 172.17.0.1 -p it is giving
ERROR 1130 (HY000): Host '172.x.x.x' is not allowed to connect to this MySQL server
Is anything i am missing?
You need to add the line below and remove other bind-address configuration in order to be able to receive connections from localhost and other available interfaces :
bind-address = 0.0.0.0

Allowing remote connections to MySQL in Ubuntu Server

I am experiencing some difficulties to configure MySQL Server and allow remote connections. I am currently using Ubuntu Server 16.04 and the latest MySQL version. This is a Virtual Private Server (VPS) from VpsDime (I apologize if this is not relevant). Everything i have done has been accomplished by SSH protocol using the root user.
This is the error Workbench throws me when I try to connect to MySQL:
Your connection attempt failed for user 'globalAdmin' from your host server at <IP>:3306:
Can't connect to MySQL server on '<ServerIP>' (10060).
I have been following and reading tutorials to configure it at this point. So, the relevant things i have done for this are:
Install the latest version of MySQL
Create a user granting full privileges for local and outsiders by this way:
CREATE USER 'myuser'#'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'#'%' IDENTIFIED BY 'mypass';
GRANT ALL ON *.* TO 'myuser'#'localhost';
GRANT ALL ON *.* TO 'myuser'#'%';
I modified the MySQL configuration file /etc/mysql/mysql.conf.d/mysqld.cnf using nano. The change i made was replacing this:
bind-address = 127.0.0.1
For this:
bind-address = 0.0.0.0
This is to allow remote connections, this was suppose to be done in my.cnf file, but i modified another file based on the first answer here: https://askubuntu.com/questions/699903/why-is-etc-mysql-my-cnf-empty
Also i added the following two lines in my file.
[mysqld]
bind-address = 0.0.0.0
Finally, using UFW I am allowing the port 3306 and 3306/tcp. Using the command sudo ufw status I am getting this (i am showing only the relevant):
3306 (v6) ALLOW Anywhere (v6)
3306/tcp (v6) ALLOW Anywhere (v6)
Which as far I know is all I need to connect remotely.
The way I am connecting to MysQL server is by MySQLWorkbench for Windows, Connection Method: Standard(TCP/IP) using my server ip address, default port (3306), the "globaAdmin" user I created as mentioned before without Schema.
---The following MAY NOT be relevant---
Im having the same issue for MongoDB, it is funny because I also installed MS SQL Server 2017 and the only thing i did to connect remotely was open ports for it with the UFW tool.

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.