Mysql can connect, but PHP can't?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • atlasyeo@gmail.com

    #1

    Mysql can connect, but PHP can't?

    Hi, my first time posting on a newsgroup. anyway, let's cut to the
    chase.

    I'm trying to migrate mysql database form one server to another server.
    So I copied the data from /var/lib/mysql to the other one.. and use
    INSERT INTO from the old database to the new one..so the Top level
    'mysql' database has all the correct users and password and priviledge.

    however, when one of the php website trying to load..it'll say

    Unable to login to the MySQL database 'tikiwiki' on 'localhost' as user
    'user1'
    Go here to begin the installation process, if you haven't done so
    already.

    Can't connect to local MySQL server through socket
    '/var/lib/mysql/mysql.sock' (13)

    However, when i do it on shell.

    shell> mysql -u user1
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 8 to server version: 3.23.58

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

    mysql> use tikiwiki;
    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> status
    --------------
    mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386)

    Connection id: 8
    Current database: tikiwiki
    Current user: user1@localhost
    Current pager: stdout
    Using outfile: ''
    Server version: 3.23.58
    Protocol version: 10
    Connection: Localhost via UNIX socket
    Client characterset: latin1
    Server characterset: latin1
    UNIX socket: /var/lib/mysql/mysql.sock
    Uptime: 1 min 24 sec

    Threads: 1 Questions: 227 Slow queries: 0 Opens: 179 Flush tables: 1
    Open tables: 64 Queries per second avg: 2.702
    --------------

    mysql> quit



    looks like it's working?? mysql can connect? but the stupid PHP cannot?
    WTF!?

    Any help is appreciated, thanks.

  • Gordon Burditt

    #2
    Re: Mysql can connect, but PHP can't?

    >I'm trying to migrate mysql database form one server to another server.[color=blue]
    >So I copied the data from /var/lib/mysql to the other one.. and use
    >INSERT INTO from the old database to the new one..so the Top level
    >'mysql' database has all the correct users and password and priviledge.
    >
    >however, when one of the php website trying to load..it'll say
    >
    >Unable to login to the MySQL database 'tikiwiki' on 'localhost' as user
    >'user1'
    >Go here to begin the installation process, if you haven't done so
    >already.
    >
    >Can't connect to local MySQL server through socket
    >'/var/lib/mysql/mysql.sock' (13)[/color]

    perror 13
    Permission denied

    It's a UNIX permission problem on the socket.
    [color=blue]
    >However, when i do it on shell.[/color]

    Try it again, on a shell RUNNING AS THE USER PHP (Apache) RUNS AS.
    My guess is that this user doesn't have permissions on
    /var/lib/mysql or /var/lib/mysql.sock . Or it might be permissions
    on /var/lib or /var, but that's less likely.

    Gordon L. Burditt

    Comment

    • atlasyeo@gmail.com

      #3
      Re: Mysql can connect, but PHP can't?

      Thanks for the suggestion, as you said, it's very unlikely.

      the mysql.sock ishave a permission like this.
      srwxrwxrwx 1 mysql mysql 0 May 9 13:30 mysql.sock

      which should be accessible by everyone.

      I have another php program calling the database that I migrated and it
      worked fine..so i'm really puzzled and scratching my head hard.

      a netstat -ln | grep mysql showed this
      unix 2 [ ACC ] STREAM LISTENING 1912679
      /var/lib/mysql/mysql.soc

      so it is listening for connection...

      gah....this is really killing me...

      Thanks for the suggestion though.

      Comment

      • Gordon Burditt

        #4
        Re: Mysql can connect, but PHP can't?

        >Thanks for the suggestion, as you said, it's very unlikely.[color=blue]
        >
        >the mysql.sock ishave a permission like this.
        >srwxrwxrwx 1 mysql mysql 0 May 9 13:30 mysql.sock
        >
        >which should be accessible by everyone.[/color]

        So what are the permissions on /var/lib/mysql?
        That matters.
        [color=blue]
        >I have another php program calling the database that I migrated and it
        >worked fine..so i'm really puzzled and scratching my head hard.[/color]

        It could also happen that PHP and MySQL disagree on where the
        socket is located.

        If you have another PHP page that can access MySQL, running the same
        instance of PHP on the same system running Apache, something wierd is
        going on.

        How did you migrate the database? If you did a UNIX-level copy,
        it is possible that some of the files in the database have the wrong
        owner so *MySQL* can't read/write them.

        [color=blue]
        >
        >a netstat -ln | grep mysql showed this
        >unix 2 [ ACC ] STREAM LISTENING 1912679
        >/var/lib/mysql/mysql.soc
        >
        >so it is listening for connection...[/color]

        An error of 'permission denied' means it can't open the socket (or
        some file), which is pretty much independent of whether anything
        is listening on it or not.

        Gordon L. Burditt

        Comment

        • atlasyeo@gmail.com

          #5
          Re: Mysql can connect, but PHP can't?

          Cool, this sounds a lot more sense...

          ok.. on /var/lib/mysql
          drwxrwxr-x 19 mysql mysql 4096 May 9 13:30 mysql
          that's the permission.

          I did a Unix level copied on all the mysql data. Except I did an INSERT
          command for the new server's mysql database to obtain user's account
          and priviledge. and then did a GRANT ALL to all the database.

          How can we address the "ownership" issue on the mysql database? I think
          this might be the problem..howeve r, I thought if i did a mysql -u user
          to connect and change to that database, since i can do it..i assumed
          the priviledge is fine? no?

          thanks again.

          Comment

          • Gordon Burditt

            #6
            Re: Mysql can connect, but PHP can't?

            >Cool, this sounds a lot more sense...[color=blue]
            >
            >ok.. on /var/lib/mysql
            >drwxrwxr-x 19 mysql mysql 4096 May 9 13:30 mysql
            >that's the permission.
            >
            >I did a Unix level copied on all the mysql data. Except I did an INSERT
            >command for the new server's mysql database to obtain user's account
            >and priviledge. and then did a GRANT ALL to all the database.
            >
            >How can we address the "ownership" issue on the mysql database? I think
            >this might be the problem..howeve r,
            >I thought if i did a mysql -u user[/color]

            "mysql -u user" is a *MySQL* user name (and permission issue), not
            a *UNIX* user name (and permission issue), even if the names happen
            to be the same (and they very often are, for administrative
            convenience). For a UNIX permission problem, the MySQL client
            and/or server code is having problem accessing files MySQL is
            supposed to control, but doesn't.
            [color=blue]
            >to connect and change to that database, since i can do it..i assumed
            >the priviledge is fine? no?[/color]

            Do a "ls -alR" on /var/lib/mysql and look at ownership and permissions
            on *ALL* the files, especially the ones you copied. They all should
            be owned by user mysql, group mysql. Not all methods of doing a
            Unix level copy preserve this. (Having user 'mysql' have different
            uids on different systems can also confuse the issue, especially
            if NFS mounts are involved.) Directories should have at least rwx
            for the owner (user mysql). Files should have at least rw for the
            owner (group mysql). Symlinks, if any, may have odd owners because
            on some systems symlinks don't actually HAVE real owners. Just make
            sure the symlinks point to a sane place.

            Gordon L. Burditt

            Comment

            • atlasyeo@gmail.com

              #7
              Re: Mysql can connect, but PHP can't?

              Yeah, I have checked all the unix permission, it's all belonged to
              mysql, group mysql, with permission of 775, rwx-rwx-rw, i also ensure
              it by doing a chmod -R command on all of the files under
              /var/lib/mysql.

              Comment

              • atlasyeo@gmail.com

                #8
                Re: Mysql can connect, but PHP can't?

                Gordon, first of all, I would really want to thank you, for even
                willing to help out, thanks man..you da man.

                Finally, Mystery resolved, this box is a Fedora Core 3, and I think I'm
                so used to the old RH that I've missed the new SELinux feature, which
                is installed by default.

                This extra security feature is having a lot of restriction being set on
                apache's behavior and how it access the data.

                Once I disable it by using the system-config-securitylevel command,
                whole thing works like a charm.

                phew......man.. SELinux....what the...

                Comment

                Working...