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
Related
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
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.
I need to access my MariaDB installation from another PC on my local network but get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.127' (111)
I know this is because it's bound to localhost but I can't seem to find the relevant config file. I have tried several but it looks like this:
/etc/mysql/mariadb.conf.d/50-server.cnf
is the only one with settings in it but after restarting I still cannot access. As a test I temporarily changed the port to 3305 from 3306 and running lsof -i -P | grep :3306 still showed mysql running on 3306 so I know the settings are not taking.
Where is the config file or am I missing something?
I just figured out what was wrong:
/etc/mysql/mariadb.conf.d/50-server.cnf
Is the correct file but for some reason
service mysql restart
Didn't take so I tried rebooting and it's fixed! Hope this helps someone..
I deploy a mysql service on my company remote develop CentOS machine, I'm sure the service is turn on, and it can be access from an other reomte linux machine.
However, I can't connect it from my own Windows PC. I tried mysql workbench client and HeidiSQL client, both failed. I can ping through the remote IP address. I have tried anything I can found on google. Like
add bind-address = 127.0.0.1 to cnf file, and comment out the skip-networking.
I also tried the answer on another question Can't connect to remote server using MySQL Workbench on mac, which allow all machine can access to the service.
But my PC still can't connect to it, which report code 10060 error. So what should I do?
That bind-address = 127.0.0.1 config option means that your mysql server only accepts connections from the localhost, which is your actual CentOS machine. Make sure to set bind-address = 0.0.0.0.
Also, make sure that:
you have connectivity from your windows machine to the CentOS one
no firewall blocks the external connections to the local mysql port
Regarding potential security concerns from opening your mysql instance to the whole internet - first make it work, then make it better
I had the same issue here man,and i discovered that we need to create a user that isnt the root user. I my case, i don't know why yet, the issue was that.
The solution
Steps:
1 - Check the firewall (create a rule for port 3306 or disable it).
2 - Comment the line # bind-address=0.0.0.0 at [mysqld] config optin in C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
3 - Create the user to remote access:
mysql> CREATE USER 'net'#'%' IDENTIFIED BY '123';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'net'#'%' WITH GRANT OPTION;
In my case, solved.
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.