If the database host is the same computer, use localhost . MySQL will connect with a local socket, not tcpip (network) when you use localhost with a port number or not.
Sometimes the server does not support socket connections, and you get an error, for example:
Failed to connect: unable to connect to local MySQL server via socket ...
EDIT / FIXED: If you cannot connect via a socket, use 127.0.0.1 . This will force conncetion tcpip.
If the database server is installed on another computer, you can use IP address or domain .
In most cases, the IP address is better because the connection can be established even when the DNS (domain name server) is not working correctly or after the domain expires.
And one piece of advice is to use mysqli_ instead of mysql_ functions in a new application. New features are very similar in use, but more secure.
The old mysql_ functions are deprecated, and they are not recommended for new applications. They are still available in PHP due to compatibility with old obsolete software (CMS systems, e-commerce systems, etc.
PHP help says (about mysql_connect):
Using this extension is not recommended. Instead, MySQLi or PDO_MySQL should use the extension.
Learn more about connecting with localhost - information from MySQL Reference
On Unix, MySQL programs handle the localhost hostname specifically, in a way that is likely different from what you expect compared to other network programs. To connect to the local host, MySQL programs try connecting to the local server using a Unix socket file. This happens even if the -port or -P option is specified to specify the port number. For the client to make a TCP / IP connection to the local server, use -host or -h to specify the host name value 127.0.0.1
Please note that the "-port" and "-P" options are described in a different context, except for PHP, but the connection mechanism works in a similar way, and localhost is a "special" name, it does not matter if it is PHP, the console or some other software security.