Professional Web Applications Themes

[newbie] not a very auspicious start - MySQL

Hi my initial forays into MySQL and PhP aren't going well, and I think well if I'm stumped _this_ early in the game... :( I use the following file on my webserver, which I've named 'test.php'.. <?php $dbhost='localhost'; $dbname='mydb'; $dubuser='user'; $dbpass='GTEGF65'; $conn = mysql_connect($dbhost, $dubuser, $dbpass) or die ('Cannot connect to DB!!'); ?> The result when I load that? Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /usr/local/www/data/.php/test.php on line 8 Cannot connect to DB!! The paths etc. have been changed, of course. Now if I do ... % mysql -A -u user mydb ...

  1. #1

    Default [newbie] not a very auspicious start

    Hi
    my initial forays into MySQL and PhP aren't going well, and I think
    well if I'm stumped _this_ early in the game... :(

    I use the following file on my webserver, which I've named 'test.php'..

    <?php

    $dbhost='localhost';
    $dbname='mydb';
    $dubuser='user';
    $dbpass='GTEGF65';

    $conn = mysql_connect($dbhost, $dubuser, $dbpass)
    or die ('Cannot connect to DB!!');
    ?>

    The result when I load that?

    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local
    MySQL server through socket '/var/mysql/mysql.sock' (2) in
    /usr/local/www/data/.php/test.php on line 8
    Cannot connect to DB!!

    The paths etc. have been changed, of course.

    Now if I do ...

    % mysql -A -u user mydb -pGTEGF65

    .... I get...

    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 22
    Server version: 5.0.41 MySQL Community Server (GPL)

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql>

    In other words, it works. So why can't I connect from within a php file?
    The password is _identical_ (I even copied and pasted it to make sure).
    This is annoying .. is there a typo that I can't see, or is it something,
    like some sort of 'rite of passage' that all newbies have to go through??

    Help !!

    D.
    --
    des
    desmond Guest

  2. #2

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 

    Perhaps you don't have MySQL listening on a TCP/IP port, which is what
    PHP is expecting.

    Cheers,
    Nicholas Sherlock
    Nicholas Guest

  3. #3

    Default Re: [newbie] not a very auspicious start

    Nicholas Sherlock <com> wrote: 
    >
    > Perhaps you don't have MySQL listening on a TCP/IP port, which is what
    > PHP is expecting.[/ref]

    Interesting... the webserver is on localhost..

    A quick search of the 5.1 manual, reveals too many 'hits' for me to find
    'TCP/IP' ... can you tell me how to determine if MySQL _is_ listening on a
    TCP/IP port ..?

    Thanks
    desmond Guest

  4. #4

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 

    Do you actually have your mysql socket at /var/mysql/mysql.sock? If
    not, where is it?

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  5. #5

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote: 
    >
    > Do you actually have your mysql socket at /var/mysql/mysql.sock? If
    > not, where is it?
    >[/ref]
    /private/tmp/mysql.sock

    (it's a Mac).

    D.
    desmond Guest

  6. #6

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 
    >> Do you actually have your mysql socket at /var/mysql/mysql.sock? If
    >> not, where is it?
    >>[/ref]
    > /private/tmp/mysql.sock
    >
    > (it's a Mac).
    >
    > D.[/ref]

    Then you need to specify it in your client section of your my.cnf (or
    php.ini file). Right now PHP is using the default.


    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  7. #7

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote: 
    >> /private/tmp/mysql.sock
    >>
    >> (it's a Mac).
    >>
    >> D.[/ref]
    >
    > Then you need to specify it in your client section of your my.cnf (or
    > php.ini file). Right now PHP is using the default.[/ref]

    /private/etc/my.cnf now looks like this...

    [mysqld]
    safe-user-create
    socket=/private/tmp/mysql.sock

    [client]
    port=3306
    socket=/private/tmp/mysql.sock

    Same error.

    D.
    desmond Guest

  8. #8

    Default Re: [newbie] not a very auspicious start

    On Sun, 24 Jun 2007 15:19:35 +0200, desmond
    <org> wrote:
     
    >>
    >> Then you need to specify it in your client section of your my.cnf (or
    >> php.ini file). Right now PHP is using the default.[/ref]
    >
    >/private/etc/my.cnf now looks like this...
    >
    >[mysqld]
    >safe-user-create
    >socket=/private/tmp/mysql.sock
    >
    >[client]
    >port=3306
    >socket=/private/tmp/mysql.sock
    >
    >Same error.
    >
    >D.[/ref]

    That's the MySQL config.
    What's in your php.ini ?

    ; Default port number for mysql_connect(). If unset, mysql_connect() will use
    ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
    ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
    ; at MYSQL_PORT.
    mysql.default_port =

    ; Default socket name for local MySQL connects. If empty, uses the built-in
    ; MySQL defaults.
    mysql.default_socket =

    --
    ( Kees
    )
    c[_] You only live twice,
    Or so it seems.
    One life for yourself,
    And one for your dreams.
    You drift through the years
    And life seems tame,
    Till one dream appears,
    And love is its name. (#230)
    Kees Guest

  9. #9

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 
    >> Then you need to specify it in your client section of your my.cnf (or
    >> php.ini file). Right now PHP is using the default.[/ref]
    >
    > /private/etc/my.cnf now looks like this...
    >
    > [mysqld]
    > safe-user-create
    > socket=/private/tmp/mysql.sock
    >
    > [client]
    > port=3306
    > socket=/private/tmp/mysql.sock
    >
    > Same error.
    >
    > D.[/ref]

    Did you stop and start (not just reload) MySQL and Apache?

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  10. #10

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote: 
    >>
    >> /private/etc/my.cnf now looks like this...
    >>
    >> [mysqld]
    >> safe-user-create
    >> socket=/private/tmp/mysql.sock
    >>
    >> [client]
    >> port=3306
    >> socket=/private/tmp/mysql.sock
    >>
    >> Same error.
    >>
    >> D.[/ref]
    >
    > Did you stop and start (not just reload) MySQL and Apache?[/ref]

    Yes.

    desmond Guest

  11. #11

    Default Re: [newbie] not a very auspicious start

    Kees Nuyt <demon.nl> wrote: 
    >>
    >>/private/etc/my.cnf now looks like this...
    >>
    >>[mysqld]
    >>safe-user-create
    >>socket=/private/tmp/mysql.sock
    >>
    >>[client]
    >>port=3306
    >>socket=/private/tmp/mysql.sock
    >>
    >>Same error.
    >>
    >>D.[/ref]
    >
    > That's the MySQL config.
    > What's in your php.ini ?
    >
    > ; Default port number for mysql_connect(). If unset, mysql_connect() will use
    > ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
    > ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
    > ; at MYSQL_PORT.
    > mysql.default_port =
    >
    > ; Default socket name for local MySQL connects. If empty, uses the built-in
    > ; MySQL defaults.
    > mysql.default_socket =
    >[/ref]
    There was nothing in them but I entered 3306 and /private/tmp/mysql.sock

    Restarted apache and MySQL.

    No joy. :(
    desmond Guest

  12. #12

    Default Re: [newbie] not a very auspicious start

    desmond <org> wrote:
     

    Duh. I'd put '/private/tmp/mysql.socket'

    Removed the feral 'et' and it works.

    Thanks, guys.
    desmond Guest

  13. #13

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 
    >
    > Duh. I'd put '/private/tmp/mysql.socket'
    >
    > Removed the feral 'et' and it works.
    >
    > Thanks, guys.[/ref]

    You shouldn't need it in php.ini if your MySQL is set up properly. That
    way if you change the location of the socket you have one less file to
    remember to update.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  14. #14

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote: 
    >>
    >> Duh. I'd put '/private/tmp/mysql.socket'
    >>
    >> Removed the feral 'et' and it works.
    >>
    >> Thanks, guys.[/ref]
    >
    > You shouldn't need it in php.ini if your MySQL is set up properly. That
    > way if you change the location of the socket you have one less file to
    > remember to update.[/ref]

    But it's in my my.cnf and that doesn't change things: i still can't
    connect, unless I do the above modif to php.ini.

    D.
    desmond Guest

  15. #15

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 
    >> You shouldn't need it in php.ini if your MySQL is set up properly. That
    >> way if you change the location of the socket you have one less file to
    >> remember to update.[/ref]
    >
    > But it's in my my.cnf and that doesn't change things: i still can't
    > connect, unless I do the above modif to php.ini.
    >
    > D.[/ref]

    Is it in this my.cnf file you're using?

    I compile my own mysql and set it in that compile configuration options.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  16. #16

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote: 
    >>
    >> But it's in my my.cnf and that doesn't change things: i still can't
    >> connect, unless I do the above modif to php.ini.
    >>
    >> D.[/ref]
    >
    > Is it in this my.cnf file you're using?[/ref]

    yes..
    [mysqld]
    #Don't allow new user creation by the user who has no write privileges to
    the mysql.user table.
    safe-user-create
    socket=/private/tmp/mysql.sock

    [client]
    port=3306
    socket=/private/tmp/mysql.sock
     

    I used a binary (gettin' lazy)..
    desmond Guest

  17. #17

    Default Re: [newbie] not a very auspicious start

    desmond wrote: 
    >> Is it in this my.cnf file you're using?[/ref]
    >
    > yes..
    > [mysqld]
    > #Don't allow new user creation by the user who has no write privileges to
    > the mysql.user table.
    > safe-user-create
    > socket=/private/tmp/mysql.sock
    >
    > [client]
    > port=3306
    > socket=/private/tmp/mysql.sock

    >
    > I used a binary (gettin' lazy)..[/ref]

    Hmmm, the whole reason for having the client is to make it available to
    those who ask.

    OTOH, that may be used only for the MySQL client - I'm not sure. But
    since you got it working from the php.ini file, it looks like your good
    to go.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  18. #18

    Default Re: [newbie] not a very auspicious start

    Jerry Stuckle <net> wrote:
     
    >>
    >> I used a binary (gettin' lazy)..[/ref]
    >
    > Hmmm, the whole reason for having the client is to make it available to
    > those who ask.
    >
    > OTOH, that may be used only for the MySQL client - I'm not sure. But
    > since you got it working from the php.ini file, it looks like your good
    > to go.[/ref]

    It does..now I just need to learn php. :-\

    Thanks for the help. :-)
    desmond Guest

Similar Threads

  1. Newbie to PHP where to start
    By Hussein Patwa in forum PHP Development
    Replies: 4
    Last Post: October 26th, 08:28 AM
  2. Newbie looking where to start...
    By Domestos in forum PHP Development
    Replies: 4
    Last Post: February 17th, 01:32 AM
  3. Start 2nd swf later [newbie]
    By Mire in forum Macromedia Flash
    Replies: 0
    Last Post: October 20th, 11:52 AM
  4. newbie: How to start
    By in forum UNIX Programming
    Replies: 3
    Last Post: July 26th, 10:16 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139