I have a client on linux and the mysql server on windows
I wanted to connect to mysql remotely 2 computers can ping each other without any problem in mysql server I set the permission correctly so the specified client is allowed to connect
WIN IP: 192.168.1.2
Linux IP:192.168.1.3
in windows system:
GRANT ALL ON *.* TO 'parsa'#'192.168.1.3' IDENTIFIED BY 'parsa';
flush all privileges;
in my linux,in my.cnf I wrote this line in mysqld section
bind-address=192.168.1.2
skip-networking was commented and I didn't change it
I restarted the mysql
when I use
telnet 192.168.1.2 3306
telnet:connect to address 192.168.1.2:Connection timed out
and using this command:
mysql -h 192.168.1.2 -u parsa -p parsa
Error 2003:can't connect to mysql server on 192.168.1.2
The firewalls in both sides are disabled what should I do?
command:net stats srv
Statistics since 2/29/2012 4:52:22 PM
Sessions accepted 1
Sessions timed-out 0
Sessions errored-out 0
Kilobytes sent 0
Kilobytes received 0
Mean response time (msec) 0
System errors 0
Permission violations 0
Password violations 0
Files accessed 0
Communication devices accessed 0
Print jobs spooled 0
Times buffers exhausted
Big buffers 0
Request buffers 0
The command completed successfully.
Connection timed out can mean two things:
Your server is too busy to respond
There is a firewall between your client computer and the server which blocks the connection.
To see how busy the server is, use uptime. Load average > 10 means "busy". Load average < 1 means "idle".
If the server is idle, check for the firewall settings on the server, then check the client.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 months ago.
Improve this question
I am trying to connect my database from my Perl program on linux, it is actually a work project. I need to fetch some values which are present in different tables.
The code I am using for the connection is below :
my $dbType = "mysql";
my $database = "trustid";
my $host="XXX.XX.X.XX";
my $dsn="";
my $userid="";
my $password="";
if($dbType eq "mysql") {
$dsn = "DBI:$dbType:database=$database;host=$host:port=3306";
$userid = "user_id";
$password = 'password';
} else {
$dbType = "postgres";
$userid = "postgres";
$password = "postgres";
$dsn = "DBI:$dbType:database=$database;host=$host,port=XXXX";
}
my $dbcon = DBI->connect($dsn, $userid, $password) or
die "Can't connect to database: $DBI::errstr\n";
print "connected to the database\n";
When I am trying to execute it by ./aa.pl it is showing the following error:
root#tc-lab-02:/home/abcdefgi/Ajay_POC/XL_Parsing# ./aa.pl
DBI connect('database=abcdefgi;host=XXX.XX.X.XX:port=XXXX','trusavc_sa',...) failed: Host 'YYY.YY.Y.YY' is not allowed to connect to this MySQL server at ./aa.pl line 40.
Can't connect to database: Host 'YYY.YY.Y.YY' is not allowed to connect to this MySQL server
I have changed the user to the root, still I am unable to make the connections.
You need to connect to localhost (instead of XXX.XX.X.XX) if the database server is local (i.e. on the same machine as the Perl program).
If the database is remote, you'll need to create a tunnel to that machine's localhost, or you'll need to adjust the MySQL server's configuration to accept connections from your machine.
When communicating over the internet, one doesn't communicate with a machine so much as with a network adapter on that machine. A machine might have multiple network adapters, each with its own network address. These logical network adapters correspond to physical network adapters (e.g. ethernet, wifi, etc) and to virtual network adapters (e.g. an interface between a host system and a VM hosted on that system).
All internet-capable systems have a special virtual adapter known as the loopback adapter. This is the one assigned the IP address to which localhost resolves (usually 127.0.0.1 [IPv4] and/or ::1 [IPv6]).
What's special about this adapter is that it can only be used to communicate with itself. This means two things:
When you communicate with localhost, you also communicate from localhost.
When you communicate to something other from localhost, you also from something other than localhost.
For security reasons, MySQL only authorizes connections from this interface by default. This ensures that you only expose your database to programs running on your system.
But because of the "rules" listed above, it means you must connect to localhost to access your database, not some other interface such as a your ethernet or wifi interface.
For example, consider a system with these interfaces:
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.24.241.85 netmask 255.255.240.0 broadcast 172.24.255.255
inet6 fe80::215:5dff:feef:f494 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:ef:f4:94 txqueuelen 1000 (Ethernet)
RX packets 620620 bytes 187701194 (187.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 179 bytes 12626 (12.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(This is from Linux. On Windows, you can use ipconfig, but newer version don't actually show the loopback adapter.)
If this machine runs MySQL with its default configuration, it will listen to all interfaces for connections. However, it will only authorize connection coming from 127.0.0.1 and from ::1.
This can be achieved by connecting to 127.0.0.1 or ::1, but it can't be achieved by connecting to 172.24.241.85 or fe80::215:5dff:feef:f494. The latter two would reach the MySQL server (since it listens to all interfaces on the machine), but it would reject the connection with the error message you obtained ("Host 'ADDRESS' is not allowed to connect to this MySQL server").
As the title says I want to connect remotely to mysql and it is on windows server but I got this error message.
Cant connect to mysql server on X.X.X.X
I am tring it with HeidiSql
I have MariaDB installed.
Also I can connect to server using remote connection.
Server is running and can connect to mysql localy
What have I tried:
I located my my.ini file and checked that I dont have one of these commands:
Skip-networking
bind-address = some IP
I didnt have them there in the first place
I logged in my MariaDB terminal and granted all permisions to user using this:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.100.%'
IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;
I have added port 3306 to windows firewall
I guess it is worth mentioning that I cant ping that server either
if I do
ping X.X.X.X
it returns:
Pinging X.X.X.X with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for X.X.X.X:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
I have spent many hours on forums and tried all instructions but still cant connect.
Any help would be much appreciated!
The detailed problem can be from two different causes:
First option:
MySQL is binded to 127.0.0.1 or no ip at all. Check netstat on windows cmd for locating 3306 port opened to mysql process and binded to your network LAN interface or 0.0.0.0 (not to loopback / 127.0.0.1 // ::1)
For check netstat, use netstat -a -n -o, you can see in the response the PID of the process too.
For check MySQL is working on the same machine, try to connect from local console using mysql -h 127.0.0.1 (for localhost connection) or mysql -h (your LAN IP) (If you have mysql binded only to your LAN IP address).
Second option:
If first test are OK. Maybe windows firewall is not configured correctly. Try to disable windows firewall (double check disabling it). The error response on your question are because windows firewall are active and blocking connections. When you have verified you can reach 3306 with firewall off, enable it and configure. Check always you're opening the port on the required network profile (Remember, windows firewall can have different rules for private / public connections).
For check firewall correctly configured, try to access to the 3306 port on the computer from another comp on the LAN.
If you have a huge LAN network with VLANs and similar technologies, check your routing topology. Also, remember always for initial checks, disable windows firewall. Your ping are failing because firewall are enabled.
I'm getting "'host_name' is blocked because of many connection errors". I know the reason for the failed connections, and the cause is resolved.
To reset the condition, I assume that FLUSH HOSTS needs to be run at the remote host, but I don't have sufficient (RELOAD) privilege there.
If mysql is (ever) restarted on the remote host, will the hosts cache be cleared? (as if a FLUSH HOSTS had been run)
Otherwise, will the condition persist for some period of time? Or for ever?
I can not find documentation that the information in the host cache is cleared on MySQL restart.
I have been able to get an answer in practice with MySQL 5.5...
force a host to reach max_connect_errors (telnet hostname 3306 repeatedly until it fails)
verify MySQL client connections would fail with ERROR 1129 (HY000): Host '$hostname' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
restart MySQL
successfully connect with MySQL client after the restart.
For our application, setup on the Amazon EC2 instances, we are using MySQL databases, installed on 2 EC2 instances, in master-master replication mode. To load balance these DB Servers I am using an HAProxy deployed on another EC2 instance with configuration
listen mysql <public dns of haproxy>:<port>
mode tcp
balance roundrobin
server mysql-db-s1 <elastic ip of db server1>:<port> maxconn 2000
server mysql-db-s2 <elastic ip of db server2>:<port> maxconn 2000
All three instances are assigned elastic ip's and I use the public dns of haproxy to connect from my application. But at times I get the error
`com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: C
ommunications link failure The last packet successfully received from the server was 58,085 milliseconds ago.
The last packet sent successfully to the server was 0 milliseconds ago.`
Has this anything to do with the configuration I have given here? Is it better to use the elastic ip's instead of Public DNS ?
This was not essentially an HAProxy issue, as I got the same error after I connected directly to one of the databases. Tuned the database a little and fixed some code in my application, and now I am not getting this atleast for the past 12 hours. Thanks for the suggestions. I would be moving one of the DB to another availability zone.
Web servers and databases load balancing concepts because of the request for the websites in large number. So we need to know how to handle this large number of requests through load balancing.
In this article, we are going to discuss this MySQL load balancing concepts using HAProxy. Let's consider the MySQL node 1 ip address is 192.168.1.172 and MySQL node 2 ip address is 192.168.2.82.
Step 1: Create MySQL Users And Install MySQL Client The first thing we need to make sure MySQL servers have to be configured to perform Master-Master replication as load balancing involves both reading and writing to all the backends. The initial thing we need to create a MySQL users for HAPorxy. The first user will be used by HAProxy to check the status of a server
$ mysql -u root -p -e "INSERT INTO mysql.user (Host,User) values ('192.168.1.172','haproxy_check'); FLUSH PRIVILEGES;"
$ mysql -u root -p -e "GRANT ALL PRIVILEGES ON *.* TO 'haproxy_root'#'192.168.1.172' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES"
$ sudo apt-get install mysql-client
$ sudo apt-get install haproxy
$ sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/haproxy
$ sudo nano /etc/haproxy/haproxy.cfg
and add this content to that new configuration file
global
log 127.0.0.1 local0 notice
user haproxy
group haproxy
defaults
log global
retries 2
timeout connect 3000
timeout server 5000
timeout client 5000
listen mysql-cluster
bind 127.0.0.1:3306
mode tcp
option mysql-check user haproxy_check
balance roundrobin
server mysql-1 192.168.1.172:3306 check
server mysql-2 192.168.2.82:3306 check
Step 3: Test Load Balancing
$ mysql -u haproxy_root -p -e "show variables like 'server_id'"
My app no longer connects to its DB and phpmyadmin says #1129 - Host 'xxx.xx.xx.xx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
mysql_error() prints out the same message. Could this be because of too many connections?
What causes this?
Open a command prompt (or shell in Linux) with administrative privilleges
Flush all hosts in MySQL using mysqladmin:
mysqladmin flush-hosts -u root -p
Open my.cnf (Linux) or my.ini (Windows) and change max_connect_errors variable to a large number. I used:
max_connect_errors= 1000000
Restart MySQL server
From the manual: http://dev.mysql.com/doc/refman/4.1/en/blocked-host.html
The number of interrupted connect
requests allowed is determined by the
value of the max_connect_errors system
variable. After max_connect_errors
failed requests, mysqld assumes that
something is wrong (for example, that
someone is trying to break in), and
blocks the host from further
connections until you execute a
mysqladmin flush-hosts command or
issue a FLUSH HOSTS statement. See
Section 5.1.3, “Server System
Variables”.
You could be having network problems connecting to your database.
We had this problem when using monit to monitor our DB server. Monit will cause connection errors if your config is of the form:
if failed port 3306 with timeout 15 seconds 2 times within 3 cycles then alert
Rather than
if failed port 3306 protocol mysql with timeout 15 seconds 2 times within 3 cycles then alert
The lack of 'protocol mysql' causes the connection error count to notch up.