0

Im trying to connect a vb.net2010 project to a database of a website. I have already added % as host in the remote mysql access of cpanel, and turned off my firewall.

Here is the code I used:

    Dim MySQLconn As New MySqlConnection
    MySQLconn = New MySqlConnection("server=www.mysite.net; User Id=myusername; pwd=mypassword; database=mydatabase; port=3306;")
            Try
                MySQLconn.Open()
                MsgBox("Sucess", vbOKOnly)
                MySQLconn.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

An error is caught which says "Unable to connect to any of the specified MySQL hosts"

I hope I can get help or suggestions.

Thank you.

1 Answer 1

3

Please verify that the MySQL server listens on external interfaces.

In most *nix Environments it defaults to localhost, that means you can't connect from a remote machine, even if you disable a firewall.

This is either achived via skip-networking or more common via bind-address localhost in the my.cnf file.

Try setting

bind-address x.x.x.x 

where x.x.x.x is the IP adress of www.mysite.net and restart your mysql server.

Update

As you are using cpanel, have you whitelistet your ip adress as mentioned here? http://kb.liquidweb.com/enable-remote-mysql-connections-in-cpanel/ http://www.yourhowto.net/how-to-make-a-remote-mysql-connection/

Basically there are three things to do:

  1. Whitelist your IP or % as a wild card (you already have done this)
  2. Add Firewall rules (not sure if that is required for cpanel, you could verify that with a port scanner
  3. Your user needs permission to access the database (GRANT ... ON ... TO user@%) from a remote host. If you run this command from a command prompt you should get a password prompt >mysql -h www.mysite.net -u user -p, try to log in. If you get an access denied for user@% you need to grant permissions for user@your-ip-address-or-hostname.
Sign up to request clarification or add additional context in comments.

9 Comments

Id just like to clarify if where can I edit the bind-address? I only have access to the Cpanel of the website. I already added '%' as access host under 'Manage Remote MySQL Access' of Cpanel
I added another link yourhowto.net/how-to-make-a-remote-mysql-connection which should help.
Sir can I ask what particular tool can I use to be able to edit this bind-address? or where exactly can I edit this? I have read that this is in a "my.cnf" file and can be accessed via SSH. This is the only alternative I haven't tried. Thank you for helping.
The file is usually located in the /etc or /etc/mysql directory. Excute this command to figure out where find / -name my.cnf However, tools like plesk or cpanel normally store the system configuration somewhere else and overwrite config files evertime you change something in the webgui. That means your change propably won't last forever, but to track down the issue is worth a try. It also could be that cPanel uses a config file on a different location. On a side note: If your server has multiple ip-adresses, you can bind to any address with bind-address 0.0.0.0
How can I get into /etc or /etc/mysql directory? Is this located in the server itself? All I have access is to cPanel.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.