On Thu, Aug 01, 2024 at 14:47:49 +0000, fxkl4...@protonmail.com wrote:
> i have mysql on host1
> i created a user for mysql so i could have access from 192.168.1.%
> that works fine
> on host2 i use "mysql -u user1 -p --host=host1" and it works
> if on host1 i use "mysql -u user1 -p --host=host1" it fails
> ERROR 1045 (28000): Access denied for user 'user1'@'localhost' (using 
> password: YES)
> in /etc/hosts i have "127.0.1.1 host1.my-network host1"
> if i comment this line out, accessing mysql from host1 works

Take one more step back:

Do you have a local area network, with two or more hosts on it, and does
each of those hosts have an assigned IP address?

I.e. is host1 *always* 192.168.1.5?

If that's the case, then the correct fix is to change the 127.0.1.1 line,
replacing 127.0.1.1 with the assigned IP address (192.168.1.5 or whatever
it is).

The 127.0.1.1 is a fallback for systems where the IP address isn't fixed.
It guarantees that your system will be able to look up its own hostname
and get *some* kind of working IP address.  But if you have a fixed IP
address, you should use that instead.

If your hosts are getting their IP addresses by DHCP, and you'd like them
to get the same address every time so that you *can* make this change to
your /etc/hosts files, then you'll want to tell your DHCP server to assign
a fixed IP address to each MAC address.

Reply via email to