Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

coder_uzb's avatar

Can't connect to MySQL server on '127.0.0.1' (4)

Hi guys. When I want to connect to database. I have the following error. Can't connect to MySQL server on '127.0.0.1' (4) on sequel pro. I re-install all (vagrant,homesteadt). How can I fix it?

0 likes
6 replies
Tray2's avatar

Mysql is running on a virtual machine and you are trying to connect to your local machine. Change 127.0.0.1 (Local machine) to your vagrant installations ip. Then it should work.

Tray2's avatar

Homestad is running on a virtual machine and if you want to connect to the mysql server running on it from you local machine you need to specify the virtual machines ip.

coder_uzb's avatar

I understand you. My virtual machine's virtual ip is 1270.0.1

Tray2's avatar

run ifconfig on your virtual machine and check the ip.

You probably have two sets where one is 127.0.0.1 which is localhost on all machines. You should use the other.

It probaly looks something like this

enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.4 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::92e6:baff:fe57:4fb2 prefixlen 64 scopeid 0x20 ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet) RX packets 4543804185 bytes 6665203247515 (6.6 TB) RX errors 0 dropped 243107 overruns 0 frame 0 TX packets 1391650929 bytes 452515262486 (452.5 GB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 14213 bytes 1102344 (1.1 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 14213 bytes 1102344 (1.1 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

toby's avatar

As @Tray2 mentioned, homestead is a VM which means it has it's own IP address.

127.0.0.1 is always the localhost aka the current machine. If you want to connect to homestead's MySQL database, you need to connect to homestead's IP; typically it is 192.168.10.10.

You need the same IP if you update your /etc/hosts file (e.g. 192.168.10.10 laravel.test).

Please or to participate in this conversation.