SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    mySQL on mac (10.6.6) -- simple question

    I just installed mySQL server on my mac (10.6.6); to set up followed instructions here:
    Installing MySQL on Mac OS X Thoughts by Techxplorer

    am trying to connect with PHP, connection is failing, and have a feeling I have wrong server/host param..

    $dbhost = "localhost:3306";
    $dbuser = "root";
    $dbpass = "<pswd>";
    $dbname = "mydb";
    $dbconn = mysql_connect($dbhost,$dbuser,$dbpass) or die("Could not connect");
    print "Connected successfully<br>";


    tried with and without port.. is 'localhost' correct for host? (in windows it would be, not sure about on the mac/unix..)

    thank you..

  2. #2
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    tried to edit, didn't work.. now don't see 'edit' link...

    url I meant to post was:
    Installing MySQL on Mac OS X Thoughts by Techxplorer

  3. #3
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    SOLVED -- it's 127.0.0.1, instead of localhost (connected from JSP/Tomcat now too.. in there can be either localhost or 127.0.0.1; but in PHP it has to be the IP addresss...)

    (and, funny, don't need port (localhost:3306) like you do in windows... )

  4. #4
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't need to be the IP address, it can be simply localhost you likely don't need the port number.

    I've always used localhost in all the scripts I've written in PHP.

  5. #5
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guelphdad View Post
    Doesn't need to be the IP address, it can be simply localhost you likely don't need the port number.

    I've always used localhost in all the scripts I've written in PHP.

    weird... I tried again with 'localhost' in PHP before posting my last response.. it didn't work... only works with the IP address...

    thank you..

  6. #6
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In mysql client run the following:
    Code:
    USE mysql;
    SELECT user, host FROM user;
    does it show 127.0.0.1 or localhost under the host column for the user you've logged in with?

    Just realizing your setup may have the former rather than latter. haven't set up a mac in a while.

  7. #7
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    mysql> use mysql
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> select user, host from user;
    +------+------------------------------------+
    | user | host                               |
    +------+------------------------------------+
    | root | 127.0.0.1                          |
    | root | ::1                                |
    |      | <myName>s-MacBook-Pro.local        |
    | root | <myName>s-MacBook-Pro.local        |
    | root | localhost                          |
    +------+------------------------------------+
    5 rows in set (0.00 sec)

  8. #8
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you see that you have both 127.0.0.1 and localhost for root user so both of them should work.

  9. #9
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    825
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    yes for some reason in PHP it only works with IP address.. I tried many times... (in JSP it works with both the IP add and 'localhost'....)

    go figure...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •