I have a website and I am trying to make a database connection. I am in MySQL but I don't see any information related to the hostname. localhost worked for me but I don't know the logic behind it. Please guide.

  • Can you clarify your question, please? It's unclear what you're asking. What are you trying to do? – John Conde Aug 28 '13 at 12:17

If you're wanting information on the meaning of localhost you've probably put this question in the wrong place. That question is more of a networking type question. Unfortunately, serverfault would probably consider this question as off topic too so I'll just go ahead and answer it for you and see what happens...

localhost is an alias for the current computer. It will resolve to the IP address is what is known as a loopback address. A loopback address is one which is never routed or accepted by remote computers it is therefore only valid to the local machine.

If you were connecting to another computer then you would use the hostname or IP of that computer in place of localhost. MySQL uses TCP\IP for all remote connections (which is good for us because that is the same network protocol as is used on the rest of the Internet).

If you are making a website and that website will be hosted on the local machine as well then just by connecting through localhost you know you'll be OK. If you website is somewhere else then you'll need to configure it for remote access if you want your site to use it. The way to do that has been answered a lot so I'll just link to it: https://stackoverflow.com/questions/10835676/how-to-enable-root-access-to-remote-when-configure-mysql-instance

EDIT: When giving a hostname you will not add anything to it. If your site was sample.com, then you should only use that. Do not use http://sample.com because that is not valid. You want a domain name NOT a URL. The http part is a protocol specifier; MySQL uses it's own protocol (built on the TCP\IP stack) which is the default and only protocol it knows. Also, you would ONLY put www. before your domain name IF you also have a DNS alias setup which points www.sample.com to sample.com.

EDIT2: In order for me to tell you exactly WHY what you've done didnt' work I'd need to know specifics. Once you knew those specifics I'd imagine you'd have no reason to ask this question. What you'll need is the information your web host has provided about the MySQL server. Usually, it is located on the same server as the website but the better hosts will provide a separate server for your DB. The exact information you'll need is going to be in an email they sent you when you signed up as well as a FAQ or Help section of their site. If you have a dedicated server you may be responsible for setting up your own MySQL instance on your server. In that case the hostname is going to be the same as your servers' hostname.

| improve this answer | |
  • Thanks. I had placed the url of the website without http and www but it did not work. Logically, it should have routed back to the place where it started but it did not. What could be the reason? Thanks. – user2930 Aug 28 '13 at 13:06
  • OK, I've added more to help you with your specific problem. – krowe Aug 28 '13 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy