473,226 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 5542
>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
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
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
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
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
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
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
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
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
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.