If the MySQL server is localhost for your scripts then it's running on the same physical machine as your website files.
Therefore you can use the IP address, your website's domain name, whatever - the key is that all the varioous schemes point to the same physical machine.
By default you can only access the database locally and you need to explicitly grant access to other hosts. You can do this with the cPanel MySQL Databases tab - see the list there, only localhost is included as default. Add your IP address and you'll be able to connect
Other control panels should have similar options and of course you firstly need to check if your host has port 3306 available which you can do via start > run > 'cmd' > enter > 'telnet [domain name] 3306' > enter, without the square brackets.