By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

Mysql can connect, but PHP can't?

P: n/a
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.

Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
>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)
perror 13
Permission denied

It's a UNIX permission problem on the socket.
However, when i do it on shell.


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
Jul 17 '05 #2

P: n/a
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.

Jul 17 '05 #3

P: n/a
>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.
So what are the permissions on /var/lib/mysql?
That matters.
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.
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.


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

so it is listening for connection...


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
Jul 17 '05 #4

P: n/a
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..however, 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.

Jul 17 '05 #5

P: n/a
>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..however,
I thought if i did a mysql -u user
"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.
to connect and change to that database, since i can do it..i assumed
the priviledge is fine? no?


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
Jul 17 '05 #6

P: n/a
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.

Jul 17 '05 #7

P: n/a
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...

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.