Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
04-13-2005, 11:49 PM
|
#1
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Rep:
|
Error connecting to MySQL from PHP
I am new to PHP and MySQL.
In case of entering into MySQL if I enter the following command
Code:
>$ mysql -h host_name -u user_name -p
password : xxxx
I can easily enter into mysql server and I can do what I need.
The problem is that if I enter the same from PHP with the following command :
Code:
$link=mysql_connect ('host_name', 'user_name', 'password') OR die('ERROR : ' .mysql_error())
I am getting an error :
Quote:
ERROR : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
|
Where is the problem? How do I rectify it? Please need your best suggestion.
Regards
anindyanuri
|
|
|
04-14-2005, 05:02 PM
|
#2
|
Member
Registered: Oct 2003
Location: Newport News, Va
Distribution: Debian
Posts: 246
Rep:
|
Does /var/lib/mysql/mysql.sock exist?
|
|
|
04-14-2005, 05:21 PM
|
#3
|
Member
Registered: Feb 2004
Posts: 781
Rep: 
|
Hello!
Have you compiled your PHP wright?
Look where you have your mysql.sock
Code:
$ mysql -h host_name -u user_name -p
Enter password:
mysql> status
--------------
...
UNIX socket: /tmp/mysql.sock
...
--------------
I think you need to compile PHP like this
Code:
./configure ... --with-mysql-sock=/tmp/mysql.sock --with-mysql=/path/to/mysql_directory/
If it doesn't work, create a php file with this code
PHP Code:
<?php
phpinfo();
?>
Start it in the browser and look if MySQL is enabled.
Hope this helped!
Boby
|
|
|
04-14-2005, 05:28 PM
|
#4
|
Senior Member
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794
Rep: 
|
Try 127.0.0.1 instead of localhost for the hostname. Then what happens?
|
|
|
04-14-2005, 05:41 PM
|
#5
|
Member
Registered: Oct 2003
Location: Newport News, Va
Distribution: Debian
Posts: 246
Rep:
|
If the socket location is the problem as Boby suggests, instead of recompiling php you could:
a. edit the "mysql.default_socket =" line in php.ini
or
b. create a symlink from /tmp/mysql.sock to /var/lib/mysql/mysql.sock
Last edited by twsnnva; 04-14-2005 at 05:42 PM.
|
|
|
04-14-2005, 10:04 PM
|
#6
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Quote:
Originally posted by twsnnva
Does /var/lib/mysql/mysql.sock exist?
|
Yes, it does. Giving you the effect of ls-l /var/lib/mysql/
Code:
$ ls -l /var/lib/mysql/
total 36
drwx------ 2 mysql mysql 4096 Apr 3 18:40 menagerie
drwx------ 2 mysql mysql 4096 Apr 1 22:27 mydata
drwx------ 2 mysql mysql 4096 Mar 26 23:12 mysql
srwxrwxrwx 1 mysql mysql 0 Apr 15 08:24 mysql.sock
drwx------ 2 mysql mysql 4096 Mar 26 23:12 test
Regards
anindyanuri
|
|
|
04-14-2005, 10:33 PM
|
#7
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Quote:
Originally posted by Boby
Hello!
Have you compiled your PHP wright?
Look where you have your mysql.sock
Code:
$ mysql -h host_name -u user_name -p
Enter password:
mysql> status
--------------
...
UNIX socket: /tmp/mysql.sock
...
--------------
|
No, I have not compiled PHP as I am using the packaged version of PHP which comes with Fedora Core 3. I just installed it.
The mysql.sock exists in /var/lib/mysql/
Checked this status, and the result is...
Code:
mysql> status
--------------
mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386)
Connection id: 3
Current database:
Current user: anindya@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: 17 min 8 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.004
--------------
Quote:
I think you need to compile PHP like this
Code:
./configure ... --with-mysql-sock=/tmp/mysql.sock --with-mysql=/path/to/mysql_directory/
|
Friend, I am a beginner in this trade, even on Linux. You wrote './configure ...', what is these three dots? Should I provide the command as usual with these three dots? I have checked that mysql.sock exists in /var/lib/mysql/, so please take a little bit pain to send me the exact command which I have to use.
Quote:
If it doesn't work, create a php file with this code
PHP Code:
<?php
phpinfo();
?>
Start it in the browser and look if MySQL is enabled.
Hope this helped!
Boby
|
Yes, I have created a page using phpinfo; and it tells that MySQL is enabled. The output of MySQL part is...
Code:
mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.58
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient
Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
Please help me
Regards
anindyanuri
|
|
|
04-14-2005, 10:55 PM
|
#8
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Quote:
Originally posted by Proud
Try 127.0.0.1 instead of localhost for the hostname. Then what happens?
|
If i change the 'localhost' to '127.0.0.1' in my original .php file, the error message changes to :
Code:
Access denied for user: 'anindya@localhost.localdomain' (Using password: YES)
What to do?
Regards
anindyanuri
|
|
|
04-14-2005, 11:04 PM
|
#9
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Quote:
Originally posted by twsnnva
If the socket location is the problem as Boby suggests, instead of recompiling php you could:
a. edit the "mysql.default_socket =" line in php.ini
|
The extract of the above in /etc/php.ini file is :
Code:
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =
Is the above right for me?
Quote:
Originally posted by twsnnva
or
b. create a symlink from /tmp/mysql.sock to /var/lib/mysql/mysql.sock
|
I do not know how to create the symlink. Please guide me how do I do that.
Regards
anindyanuri
|
|
|
04-15-2005, 05:50 AM
|
#10
|
Senior Member
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794
Rep: 
|
Ok, you shouldn't need that symlink as the socket is already in the right place, and works for your mysql client program, just not PHP.
The socket worked for the client app but not PHP, and the tcp/ip connection worked for PHP but was told by MySQL that the user was not permitted from that hostname.
So you seem to have a problem with PHP for the socket, and maybe MySQL for the 127.0.0.1 route.
Have all apps been installed from precompiled official .rpm files? Are there any updates for FC3 regards these apps?
|
|
|
04-15-2005, 09:14 AM
|
#11
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Quote:
Originally posted by Proud
Ok, you shouldn't need that symlink as the socket is already in the right place, and works for your mysql client program, just not PHP.
The socket worked for the client app but not PHP, and the tcp/ip connection worked for PHP but was told by MySQL that the user was not permitted from that hostname.
So you seem to have a problem with PHP for the socket, and maybe MySQL for the 127.0.0.1 route.
Have all apps been installed from precompiled official .rpm files? Are there any updates for FC3 regards these apps?
|
I have updated apache before a couple of months. At that time I did not find any problem and no error message.
|
|
|
04-16-2005, 08:40 AM
|
#12
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Some improvement is there.................
If I write :
Code:
$link = mysql_connect('127.0.0.1', 'user_name', 'password')
or die('ERROR in connection : ' . mysql_error());
I am getting the error message, but if I access mysql as the default user I am being passed and there is no error. Thus, if I write the above line as follows :
Code:
$link = mysql_connect('127.0.0.1','','')
or die('ERROR in connection : ' . mysql_error());
I am not getting any error, and I can get access to the databases that comes with the mysql.
Still I get error if I want to connect the databases which I have created with my own 'user_name' and 'password'.
What is the problem? Why I cannot connect with my 'user_name' and 'password'? It is to be mentioned that my 'user_name' and 'password' is already granted for all privileges.
Please help
Anindyanuri
Last edited by anindyanuri; 04-16-2005 at 08:46 AM.
|
|
|
04-22-2005, 11:15 AM
|
#13
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Case - I
I am giving the output of 'netstat -anl' command while I am connected to mysql as user 'anindya' and host 'localhost':
Porto RefCnt Flags Type State I-Node Path
Unix 2 [ACC] STREAM LISTENING 8016 /var/lib/mysql/mysql.sock
Unix 3 [ ] STREAM CONNECTED 14886 /var/lib/mysql/mysql.sock
Case - II
This is the output of the 'netstat -anl' command whicle I am connected to mysql as admin
Porto RefCnt Flags Type State I-Node Path
Unix 2 [ACC] STREAM LISTENING 8016 /var/lib/mysql/mysql.sock
Unix 3 [ ] STREAM CONNECTED 26733 /var/lib/mysql/mysql.sock
In second case I can able to connect to mysql from PHP but in Case-I, myself fails to connect to mysql from php.
What to do?
Regards
Last edited by anindyanuri; 04-22-2005 at 11:16 AM.
|
|
|
04-22-2005, 11:08 PM
|
#15
|
Member
Registered: Jan 2005
Location: India
Distribution: Kubuntu Gutsy
Posts: 450
Original Poster
Rep:
|
Read those articles. The problem is exactly same which I am facing. Thank you Masand for your pin-point accuracy. I shall now try for the solutions, hope it will work. I'll inform what happens for me.
Regards
anindyanuri
|
|
|
All times are GMT -5. The time now is 04:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|