Accessing Mysql database from internet
Posted by: santidat (---.Red-83-35-194.dynamicIP.rima-tde.net)
Date: January 22, 2015 04:23PM

I have Wamp 2.4 installed in a PC with windows 8.1 64 bits.
I configure php to able internet connections and it is working fine.
But I have a problem when I want to connect to my Mysql database via internet from another pc as described :

I use mysql .NET connector and a VB.net program.
The connection string is : CONNG = "uid=" + usss + ";server=" + DNSS + ";pwd=" + pwdd + ";database=ROMERO;"
where usss,DNSS and pwdd are the user,dns and password. The DNS is xxx.xxx.xxx.xxx:82

When I execute the program in the local machine , I am able to connect to the database, but when I use another machine , in the LAN or in the internet, I can not connect the database.
I tried to use xxx.xxx.xxx.xxx:3306 , only xxx.xxx.xxx.xxx ... and nothing. I check and add rules in the firewall to open 3306 port and open 3306 port in my router. But nothing.

I searched in the internet but I did not find anything about this issue with mysql and wamp server.

Thanks in advance for your time and help.

Options: ReplyQuote
Re: Accessing Mysql database from internet
Posted by: RiggsFolly (---.as43234.net)
Date: January 22, 2015 04:49PM

Hi santidat,

This is not really a WAMPServer issue, its a MySQL one.

You really need to look at the MySQL manual and understand MySQL user account properly.

But my first suggestion would be to check the MySQL user account that you are using to login to MySQL with.
Remember that a MySQl user account is made up of 2 parts, the USER ex 'santidat' and the HOST ex '127.0.0.1'

Now these 2 part work together so if you are using a MySQL user that is defined to MySQL as
'santidat'@'127.0.0.1
You are actually saying that the userid 'santidat' is only allowed to login from an ip address of '127.0.0.1' and if (s)he tries to use that account from any other ip address login will be refused.


So you have to create (and use) a MySQL account that is allowed to connect to this MySQL Server from any ip address in the world ex 'santidat'@'%'
You can create new accounts either from the MySQL console or using phpMyAdmin.

Of course remember that this new account can now be hacked, so make sure you have a VERY STRONG password set for this account.
Also make sure that this new account only has access to the databases that it should be allowed access to.
This is a seterate step in the User Setup process.



You wrote
Quote

The connection string is : CONNG = "uid=" + usss + ";server=" + DNSS + ";pwd=" + pwdd + ";database=ROMERO;"
where usss,DNSS and pwdd are the user,dns and password. The DNS is xxx.xxx.xxx.xxx:82

Also remember that MySQL (by default) runs on TCP port 3306 so in the above comment the use of
The DNS is xxx.xxx.xxx.xxx:82
will not work, unless you have changed the port that MySQL Server Listens on.

I assume that you have changed the port that APACHE runs on from port 80 to port 82. However this is irrelevant in this situation. Remember you are trying to connect directly to MySQL Server and not Apache.




So now, if you have correctly Port Forwarded port 3306 on your router, you shoudl be able to connect.





Final Note
Opening yourself up to connections from the internet is a dangerous thing to do unless you really know what you are doing, so please be careful.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: Accessing Mysql database from internet
Posted by: Otomatic (Moderator)
Date: January 22, 2015 07:13PM

Hi,

I apologize for my bad English (I'm French). I hope you understand what I am trying to explain.

With MySQL users, it is necessary to pay attention to a possible ambiguity of accounts.
The user-host-password triplet words given by the one who wants to connect will not be one that will be taken into account by MySQL due to priority rules.

Different accounts created coexist, possibly with passwords or different privileges. Because wildcards and anonymous connections, it is common that a connection attempt may correspond to multiple accounts.

Here, for example, some accounts may be created.
Example User table reading via MySQL console:
SELECT User, Host, Password FROM mysql.User ;
User        Host           Password
root        localhost
tartempion  %              *EE33294C97C42FFF14EA73AB81E428A6FC7B9A8B
lui         localhost      *14E65567ABD85135DOCFD9A7083032C179A49EE7
            %
foo         localhost      *14E65567ABDB5135DOCFD9A70B3032C179A49EE7
foo         monordi
foo         192.168.1.123
foo         192.168.%
foo         %.microapp.com
foo         %
            localhost
If foo attempts to connect locally, this not only corresponds to foo@localhost but also foo@'%', ''@localhost '@'%'. However, some of these accounts are protected by a password and some not. How MySQL does choose?
-- MySQL first selects the host expressed in the most specific way (so localhost preferably at %).
-- It then chooses the name of the most specific user (so foo rather than anonymous account).
In this case, it will be well foo@localhost will prevail; foo will have to use his password.

What will happen if tartempion attempts to connect locally with his password?
C:\>mysql --user=tartempion --password=sesame --host=localhost
ERROR 1045 (28000): Access denied for user 'tartempion'8'localhost' (using password : YES)

Indeed, applying the above rules, MySQL prefers an anonymous account on a specific host to an account nominated on a generic host. It is therefore ''@localhost without password, which overrides tartempion@'%'.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.