473,503 Members | 4,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Jul 17 '05 #1
7 5559
>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
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
>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
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
>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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
4775
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
0
2876
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
0
4229
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
0
3924
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
3
17786
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
1
3358
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
15
4564
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
7
2478
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
14
6069
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.