Can't connect to MySQL server on LAN

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
svtdoug
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 05.11.2021, 01:58

Can't connect to MySQL server on LAN

Post 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
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: Can't connect to MySQL server on LAN

Post by miab3 »

Hi Doug,

Show what you have for ZConnection in .dfm and what MySQL and client version you are using

Michał
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: Can't connect to MySQL server on LAN

Post 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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 787
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Can't connect to MySQL server on LAN

Post 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.
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
svtdoug
Fresh Boarder
Fresh Boarder
Posts: 14
Joined: 05.11.2021, 01:58

Re: Can't connect to MySQL server on LAN

Post 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
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 787
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Can't connect to MySQL server on LAN

Post by aehimself »

Glad it worked out :)
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
Post Reply