Page 1 of 1
Can't connect to MySQL server on LAN
Posted: 15.11.2021, 01:38
by svtdoug
I am using Delphi 10.4 Community addition, and Zeos 7.2.14. Have written a simple app which I can connect to a MySQL on my same development computer. But when I run this app from another computer with valid hostName = IP address of the dev computer, I get a "SQL Error: Access denied for user 'root'@'2ndComputerName' (using password: Yes). Password is set correctly in ZConnection - as I can access the db from dev machine running same app. I know the Community addition has limits on Client/Server. I was hoping using Zeos would work.
Incidentally, when I connect the app running on my dev machine to HostName = IP address of same computer (192.168.2.15) I get the same error. I know, localhost or 127.0.0.1 do work. And yes, Dev machine is on a static IP address.
I have another app developed in C# which accesses same MySQL server on dev machine which i can access from 2nd computer, and it runs fine. So I know my MySQL server and the credentials are working properly. I just would rather develop in Delphi! Also, I can point this C# app on dev computer to its own IP address (192.168.2.15) and that works. Anyone have thoughts as to what may be causing the error?
Thanks much!
Doug
Re: Can't connect to MySQL server on LAN
Posted: 15.11.2021, 13:09
by miab3
Hi Doug,
Show what you have for ZConnection in .dfm and what MySQL and client version you are using
Michał
Re: Can't connect to MySQL server on LAN
Posted: 15.11.2021, 20:27
by marsupilami
svtdoug wrote: ↑15.11.2021, 01:38
I am using Delphi 10.4 Community addition, and Zeos 7.2.14. Have written a simple app which I can connect to a MySQL on my same development computer. But when I run this app from another computer with valid hostName = IP address of the dev computer, I get a "SQL Error: Access denied for user 'root'@'2ndComputerName' (using password: Yes).
Basically this is a MySQL error. Please read their documentation about users. I seem to remember that you need a user like "root@%". On my MariaDB server I do have a user called "root@192.168.1.0/255.255.255.0" that allows me to access MariaDB from our local network.
svtdoug wrote: ↑15.11.2021, 01:38
I know the Community addition has limits on Client/Server. I was hoping using Zeos would work.
Zeos works just fine.
svtdoug wrote: ↑15.11.2021, 01:38
Incidentally, when I connect the app running on my dev machine to HostName = IP address of same computer (192.168.2.15) I get the same error. I know, localhost or 127.0.0.1 do work. And yes, Dev machine is on a static IP address.
This possibly happens because you have a user "root@localhost" which is created during installation.
svtdoug wrote: ↑15.11.2021, 01:38
I have another app developed in C# which accesses same MySQL server on dev machine which i can access from 2nd computer, and it runs fine. So I know my MySQL server and the credentials are working properly. I just would rather develop in Delphi! Also, I can point this C# app on dev computer to its own IP address (192.168.2.15) and that works. Anyone have thoughts as to what may be causing the error?
Not sure what happens there. Might have to do with the ADO .Net provider. Again - please read up on MySQL and its usernames. This is an error generated by MySQL.
Best regards,
Jan
Re: Can't connect to MySQL server on LAN
Posted: 15.11.2021, 21:08
by aehimself
svtdoug wrote: ↑15.11.2021, 01:38I know the Community addition has limits on Client/Server. I was hoping using Zeos would work.
Good news for you - these restrictions only apply to components shipped with Delphi. Zeos works exactly the same if installed on Delphi 10.4.2 Community or a Lazarus IDE.
svtdoug wrote: ↑15.11.2021, 01:38I get a "SQL Error: Access denied for user 'root'@'2ndComputerName' (using password: Yes).
Access denied means that the TCP connection was established successfully, so we ruled firewalls out.
In MySQL, usernames and passwords aren't the only protection, you can actually specify FROM WHERE these credentials are considered as valid. Please make sure that your MySQL allows the user "root" to connect from the IP address of the machine your Delphi is running on.
This opens up a huge security vulnerability though, so I'd advise to create a new user for your testing apps and give read / write access ONLY on specific databases from host '%' (wildcard, means user will be able to connect from anywhere). Even if someone gets access, they cannot drop tables / change layout. Data can always be reimported from backups.
Re: Can't connect to MySQL server on LAN
Posted: 18.11.2021, 07:12
by svtdoug
THANK YOU! Michal, Jan and AE for your insight! It was the MySQL root user - Limit to Hosts Matching = localhost that was preventing me from accessing from another machine. I just made a new user and assigned it wildcard % for Host Matching. Presto.
Thanks again for your help. Zeos components are working great. Me happy camper!
Doug
Re: Can't connect to MySQL server on LAN
Posted: 18.11.2021, 09:31
by aehimself
Glad it worked out :)