14

I have developed an application in VB6, and am using an online MySQL database server for storing my application's data.

The first time I try to connect to my database server is successful, but after closing my application and starting it again I get:

Can't connect to MySQL server(10060)"

After some time (approximately 30 minutes), I can successfully connect to the database again.

  • I have given maximum values to all of MySQL system and global variables like connection_timeout, wait_timeout etc.
  • I have granted all permissions to my MySQL user.
  • The firewall on my computer is turned off.
  • All connections are properly closed when the application closes.

I have asked the technical people who provide the Online MySQL Database service and they gave me these three reasons:

  1. The local machine from where you are trying to connect is not whitelisted on the server.
  2. The maximum number of connections for the user has been exceeded.
  3. The MySQL server was down at the time (though they said that their server was not down).

How can I solve the first two reasons, or determine that they are the cause of the problem? Or could there be another problem not listed there?

0

7 Answers 7

5

you need to make sure there is:

  1. a user created that has remote access for example user@'x.x.x.x'

  2. the two machines can establish a connection (they can ping each other for example or access each another by another method) the port is opened between the two machines

  3. check your configuration file my.ini/my.cnf for parameters like bind-address or skip-networking. Is there a blocking connection parameter like:bind-address=a.a.a.a or skip-networking?

  4. the service is up and running when you try to connect from the other machine

2

I spent an entire day banging my head trying to figure this out and it turned out to be that the Windows Network was set as Public instead of Private which blocks all incoming connections.

From the screenshot on tinker.com

Network profile

  • public: Your pc is hidden from other devices on the network and can't be used for printer and file sharing
  • private: For a network you trust, such as at home or work. Your PC is discoverable and can be used for printer and file sharing if you set it up.

Hope this helps someone.

1
  • 1
    With powershell you can set and query the NetConnection settings. The cmdlet Get-NetConnectionProfile gets a connection profile associated with one or more physical network adapters. A connection profile represents a network connection.
    – surfmuggle
    Oct 3, 2020 at 9:42
1

Most probably this is a networking side issue and the database service provider needs to create a new rule in firewall (iptables). Still we just need to confirm few things from the provider. As the behavior is not steady (on occasion you can connect, and sometimes not). So its not a user privilege issue (GRANT ALL ON ...)

  1. Make sure they have included MySQL listening port in to unblock/exception list of firewall. Most commonly it is 3306
  2. Try increasing the max_connection parameter in my.cnf
  3. In my.cnf make sure 'skip-networking' is commented out, Also bind-address = 127.0.0.1
  4. What is the output if we use the following from command line telnet ip_mysql_server 3306
1
  • 2
    on windows telnet is most probably not available: use powershell PS C:\Windows\system32> New-Object System.Net.Sockets.TcpClient("ip_mysql_server", 3306) Client : System.Net.Sockets.Socket Available : 78 Connected : True <== this indicates that you can reach the server ExclusiveAddressUse : False ReceiveBufferSize : 65536 SendBufferSize : 64512 ReceiveTimeout : 0 SendTimeout : 0 LingerState : System.Net.Sockets.LingerOption NoDelay : False
    – Cie6ohpa
    Jun 13, 2018 at 11:52
1

First check whether you given proper privileges to the user on your current host through which you are trying to connect to MySQL server.

  1. Check your hostname first
  2. Then login into the MySQL through super user like 'root'
  3. Check whether the privileges are provided or not select * from mysql.user where host="host_name"\G;
  4. Give all privileges first, then try to connect again.

grant all on *.* to 'user'@'host_name' identified by 'Password';

I hope this is helpful to you.

0

Provide the output of the telnet (ip): port

I had the same issue last time and the iptables is the culprit at that time.

When the server got rebooted the iptables rule turns to default and it didn't apply the filter for certain ports.

Check the iptables

0

Two things to add for mariadb users:

1) the my.cnf is for us too => there i found the bind-address = 127.0.0.1 line

2) you have to restart the service after changing the my.cnf file

Hope this helps

-1

some hosting providers block by default, the remote access to his MySql servers by security reasons. If you need to unblocking the remote access service tell them for unblocking this service.

Otherwise, test your app locally, as localhost and when this works fine, change the hostname, and so on database parameters in your app, and upload to your web hosting server, thats works fine!!!.

Take care, that your Database design checks with your local database design, this is very important!!!

I hope this is helpful to you.

1
  • 2
    Do you think they only block every second attempt? Sep 14, 2015 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.