Hi,

Glad we could get to the Y of this X/Y problem relatively quickly!

On Thu, Aug 01, 2024 at 02:47:49PM +0000, fxkl4...@protonmail.com wrote:
> i created a user for mysql so i could have access from 192.168.1.%
> that works fine

> ERROR 1045 (28000): Access denied for user 'user1'@'localhost' (using 
> password: YES)

"localhost" != 192.168.1.%. You need to add a mysql auth for
localhost as well.

> in /etc/hosts i have "127.0.1.1 host1.my-network host1"
> if i comment this line out, accessing mysql from host1 works

Your issue is that you are connecting from host1 to a thing called
host1, which is being looked up in /etc/hosts and matching the first
line there for 127.0.1.1 so it's going to the localhost interface,
which MySQL sees as "localhost", not something in 192.168.1.0/24.

You could add access for the user@localhost. Personally I also
disable host lookups in MySQL and do all access control by IP
addresses, but that won't help you here as it will still say
localhost as this isn't a DNS thing.

If host1 has a static IP address in the 192.168.1.0/24 range then it
is not necessary for that line in /etc/hosts to have "host1" on it;
you could remove "host1" from that line and add an extra line with
its real IP, like

127.0.1.1 localhost
192.168.1.x host1.my-network host1

The reason why your /etc/hosts is like this is so that your system
can resolve its own name even when it has no other IP address. If it
does have a static IP then it is safe to put that in there.

Bypassing /etc/hosts entirely would not be recommended.

Thanks,
Andy

-- 
https://bitfolk.com/ -- No-nonsense VPS hosting

Reply via email to