I woke up this morning and my frontend server could no longer connect to my mysql server. I have no idea why:
The internal ip of my frontend server is 172.31.X.X.
My db server is configured with firewall inbound rules that allow tcp connections on port 3306 via source 172.31.0.0/16
My frontend server is configured with firewall outbound rules that allow tcp connections on port 3306 to the internal ip address of my db server.
The mysql user I use is mysql_prod. These are the privileges I have granted for that user on the db server:
mysql> show grants for mysql_prod;
+--------------------------------------------------------------------------------------------------------------------+
| Grants for mysql_prod#% |
+--------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO 'mysql_prod'#'%' IDENTIFIED BY PASSWORD '*5B761DF55A90C1E168EC63A3B074A607ECC3B2CA' |
| GRANT ALL PRIVILEGES ON wordpress.* TO 'mysql_prod'#'%' |
What am I missing?
The issue occurred because the mysql bind-address was set to localhost, which prevented remote connections. I'm not too sure how this conf got reset (the app was working fine the night before). Anyways, once I fixed it, it was working fine.
Related
I've looked in so many areas to try to fix this problem and I can't seem to find a solution. Im running ubuntu linux with the latest mysql and phpmyadmin installation. I found that connecting to the database locally works but if I try to connect remotely it keeps denying the connections. The only way I can login to phpmyadmin is if I put the ip address in the bar, connecting via the web address will not work.
Are you trying to connect to MySQL remotely or PHPMyAdmin remotely?
If you are trying to access MySQL remotely, you need to do the following:
Edit the bind-address variable in /etc/my.cnf, to 0.0.0.0 or the IP address of your server
Make sure your MySQL user has permissions from remote hosts, do this using:
CREATE USER 'myuser'#'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'#'%' IDENTIFIED BY 'mypass';
Then:
GRANT ALL ON . TO 'myuser'#'localhost';
GRANT ALL ON . TO 'myuser'#'%';
Then go ahead and restart the mysql instance on your server. This also assumes you have set IP tables up to allow port 3306 TCP incoming to your server.
I'm trying to let a client on another network remotely connect to a database i;ve setup, but every time I try and setup the connection for them, i get SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'servername' (110)
I have the following:
MySQL user has been created, with the host set to the IP address of their server
my.cnf bind address has been set to 0.0.0.0
mysql service has been restarted
MySQL is running on port 3306
3306/tcp incoming is allowed in the firewall of my server
I have tested it from other servers INSIDE our network, e.g. my own local PC and from another one of our web servers, setting up a MySQL user for those specific hosts, and it works fine. It's just this one outside our network that doesn't work.
Could it be something on their end that is stopping them being able to connect? Or have I missed anything?
Thanks.
To access MySQL from outside. you should enable MySQL remote access .
Here is the way to do so:
1- Comment out following lines in Mysql Config(my.cnf)
#bind-address = 127.0.0.1
#skip-networking
2- Save the file and restart Mysql server
3- Update GRANT privilege
By default, mysql username and password you are using is allowed to access mysql-server locally. So need to update privilege.
Run following query to update privilege
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Change the 'USERNAME' to your Database user and 'PASSWORD' to User Password
I have a MySQL Server 5.5.32 running on Ubuntu 12.04. Ubuntu is being run on VM. Host platform is Windows 7. How can I connect with the Ubuntu's MySQL from Windows?
I have done the following so far:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Running a show grant for root; displays this:
+-------------------------------------------------------------+
| Grants for root#% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
But when I try to connect to this server from SQLYog running on Windows, I get an error Error 2003 Cannot connect to mysql server on '192.168.xxx.xxx'.
The IP being feed to SQLYog, I got it from ifconfig. Supplied the inet addr.
inet addr:192.168.226.xxx Bcast:192.168.226.yyy
Is the address being used is incorrect or are these grant issues? Please advice.
You problem is that (probably) your mysql is bind to 127.0.0.1 instead of 0.0.0.0.
You should change bind in /etc/mysql/my.cnf to 0.0.0.0
bind-address = 0.0.0.0
And then restart mysql of course.
In newer versions of MySQL, instead of skip-networking the default is now to listen only on localhost
bind-address = 127.0.0.1
So you need to add your machine IP to here or simply comment it out if you are not worry about security concerns.
The error message Error No. 2003: Can't connect to MySQL server on 'localhost' (or some other host)
simply means that connection is not possible for one of the following (or similar) reasons:
There is no MySQL server running at the specified host
Connection to the MySQL server is not allowed using TCP-IP. Check the 'skip-networking' setting in the MySQL configuration file (my.ini on Windows, my.cnf on Unix/Linux). It shall be commented out like '#skip-networking'. If it is not commented out, then do it and restart the MySQL server for the change to take effect. SQLyog needs to connect using TCP-IP.
Some networking issue prevents connection. It could be a network malconfiguration or a firewall issue. We have experienced sometimes that some firewalls is blocking TCP-IP connections even if it claims to be disabled. Most often it will help to uninstall and reinstall the firewall.
When trying to connect to a MySQL server at an ISP this error message often indicates that direct connection to MySQL has been blocked. You must then use HTTP-tunneling or SSH-tunneling to connect.
I think the problem is with the Network Adapter settings in your VM settings
Do like this in your VM settings.
VM Settings -> Network Adapter Settings -> Select Bridged
The VM will connect to the physical network when the network connection is on bridged mode.
Try to ping the VM host in your windows machine after changing the network connection to bridged.
If the VM is pinging in your windows machine then it will work.
Error No. 2003: Can't connect to MySQL server on '192.168.x.x'
simply means that connection is not possible for one of the following (or similar) reasons:
There is no MySQL server running at the specified host
Connection to the MySQL server is not allowed using TCP-IP. Check the 'skip-networking' setting in the MySQL configuration file (my.ini on Windows, my.cnf on Unix/Linux). It shall be commented out like '#skip-networking'. If it is not commented out, then do it and restart the MySQL server for the change to take effect. SQLyog needs to connect using TCP-IP.
Make sure that you are able to connect to MySQL port using telnet
C:\telnet hostname/IP_address port
I have a remote Server which is running mysql. I have enabled remote access by changing the bind address to the public ip, and commenting the "skip-networking" line. I then used ufw (ubuntu firewall) to open the mysql port 3306
However my client times out when trying to connect to the server. So I test the connection with telnet, and I get the expect response, the same as I get on the local server.
I'm getting no errors, and no response when using a mysql client, but access would appear to be there in telnet.
Can anybody suggest what I've missed?
Thanks
If its not a firewall issue then maybe its a permission problem , try this for the user you use to connect from that host:
CREATE USER 'user'#'host' IDENTIFIED BY 'pass';
GRANT ALL on *.* to 'user'#'host';
FLUSH PRIVILEGES;
UPDATE:
Also check the bind-address from my.cnf file
For example, if you bind to 0.0.0.0, you can connect to the server
using all existing accounts. But if you bind to 127.0.0.1, the server
accepts connections only on that address. In this case, first make
sure that the 'root'#'127.0.0.1' account is present in the mysql.user
table so that you can still connect to the server to shut it down.
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.