Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to connect with mysql_connect using PHP.

I was wondering how to find the hostname when I turn my MacBook into a server by turning on the personal webpage.

I have Apache, MySQL and PHP enabled.

Is the hostname what you ssh into? It says that my computer's name is spiderman and it could be accessed with spiderman.local, but it doesn't seem to work. I've also tried using my IP address.

share|improve this question
    
Are you SSHing into the computer from the same local network? –  daviesgeek Oct 30 '11 at 22:47
add comment

migrated from serverfault.com Oct 30 '11 at 19:42

This question came from our site for professional system and network administrators.

3 Answers

If you want to connect to MySQL running locally, try 127.0.0.1 or localhost.

share|improve this answer
add comment

In general, you get the hostname by typing

echo $HOSTNAME 

in Terminal.

But for your server setup, if no one has messed with configuration, localhost will be the hostname to use; in safe mode, localhost:3306 (that is port 3306) is the default. (cf. http://php.net/manual/en/function.mysql-connect.php )

BUT: You should make sure that you actually started the MySQL server. Starting command depends on your installation.

share|improve this answer
add comment

It depends if you are doing it from within a script program where the environment has been set up correctly, either the following may work or suit you:

~$ uname -n
roberts.e.co.za
~$ echo $HOSTNAME
roberts.e.co.za
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.