LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 06-15-2004, 06:45 AM   #1
sy-co
LQ Newbie
 
Registered: Apr 2004
Distribution: Mandrake
Posts: 28

Rep: Reputation: 15
mysql conection problem


Hi

I've just installed a binary version of mysql 4.0 downloaded from mysql.com. Installation went ok and I can connect to the database.

But my dbconnect isn't working.

error printed to PHP page reads.

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/html/emailer/dbconnect.php on line 3
I cannot connect to the database because: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The password and username are ok and I can connect using a terminal. I've tried rebooting but no joy.

Is this something to do with configuring PHP as I used a binary distribution and not an RPM? If so what change do I have to make. Or where can I read up some more.

Here's my dbconnect

$db=mysql_connect ("localhost", "usrnme", "psswd") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db("dbase",$db);

Cheers
 
Old 06-15-2004, 07:27 AM   #2
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
Re: mysql conection problem

Quote:
Originally posted by sy-co
Hi

I've just installed a binary version of mysql 4.0 downloaded from mysql.com. Installation went ok and I can connect to the database.

But my dbconnect isn't working.

error printed to PHP page reads.

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/html/emailer/dbconnect.php on line 3
I cannot connect to the database because: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The password and username are ok and I can connect using a terminal. I've tried rebooting but no joy.

Is this something to do with configuring PHP as I used a binary distribution and not an RPM? If so what change do I have to make. Or where can I read up some more.

Here's my dbconnect

$db=mysql_connect ("localhost", "usrnme", "psswd") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db("dbase",$db);

Cheers
Looks like your server isn't running!! Dis you stop yur old server before installing the new one??

What happens when you do a "telnet localhost 3306".


$ ps -ef |grep mysql

Kill all of them and then start mysql using "service mysql start" (on redhat)
 
Old 06-15-2004, 08:18 AM   #3
MunterMan
Member
 
Registered: Nov 2003
Location: The North of England
Distribution: Suse 10.3
Posts: 172

Rep: Reputation: 30
Try it without the password. eg

mysql_connect ("localhost", "username");
 
Old 06-15-2004, 11:17 AM   #4
barrys
Member
 
Registered: Sep 2003
Location: London
Distribution: Susi 9.1, Man10 amd64, Man10.1
Posts: 243

Rep: Reputation: 30
Have you loaded the mysql-php patch rpm?

urpmi php-mysql
Not loaded by default

Php will not connect with mysql without this.

have you modified php.ini at include path
erase to read only
include_path ='./''

Reload your browser.

check your mysql passwords work in a terminal

Run a text file in your browser with only the line

<? phpinfo() ?>

Seein the phpinfo at the mysql after the GETEXT

if you have the mysql .sock listed it should be in
/var/lib/mysql/mysql.sock
 
Old 06-15-2004, 09:48 PM   #5
sy-co
LQ Newbie
 
Registered: Apr 2004
Distribution: Mandrake
Posts: 28

Original Poster
Rep: Reputation: 15
Thanks for your help guys. By checking this stuff I have increased my understanding alot but have come to the end of things I can check but still cant get php to connect to mysql.

I've included the results of your suggestions below.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

The error is

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' but mysql.sock is in

/tmp/mysql.sock

Where do I make the change so PHP looks for the mysql.sock in the right place? I couldn't see it in php.ini

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

The server is definatly running

[root@localhost /]# ./usr/local/mysql-standard-4.0.20-pc-linux-i686/bin/mysqladmin -u root -ppsswrd version
./usr/local/mysql-standard-4.0.20-pc-linux-i686/bin/mysqladmin Ver 8.40 Distrib 4.0.20, for pc-linux on i686
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version 4.0.20-standard
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 18 min 21 sec

Threads: 1 Questions: 1 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.001
[root@localhost /]#

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

telnet localhost 3306 result

[root@localhost simon]# telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
0
4.0.20-standard&^*RB0jF,Connection closed by foreign host.
[root@localhost simon]#

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Tried without the password but it didnt work.

urpmi php-mysql is apparently installed

[root@localhost simon]# urpmi php-mysql
Everything already installed
[root@localhost simon]#

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Quote"
have you modified php.ini at include path
erase to read only
include_path ='./''
"

would that be this include path?

; UNIX: "/path1:/path2"
; ### MDK
include_path = ".:/usr/lib/php/:/usr/share/pear/"
;

I tried
include_path = "./usr/lib/php/:/usr/share/pear/" (without the first colon)
and
include_path = "./"

As php is working OK I didn't think it was this include path so put it back to normal but cant see another include_path in php.ini

Here is the mysql section of php.ini

\\\\\\\\
start
////////

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =

; Maximum time (in secondes) for connect timeout. -1 means no limimt
mysql.connect_timeout = 60

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Erros will be displayed.
mysql.trace_mode = Off

\\\\\\\\
end
////////

I tried adding /tmp/mysql.sock to
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock

but no joy.

Mysql passwords definatly work in a terminal and there isn't a typo in the dbconnect file.

Here's the mysql relevant bit from phpinfo().

MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.0.18
MYSQL_MODULE_TYPE none
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE no value
MYSQL_LIBS no value


MYSQL_SOCKET still doesn't read /tmp/mysql.sock even after change php.ini default socket name.

Cheers
 
Old 06-15-2004, 10:08 PM   #6
sy-co
LQ Newbie
 
Registered: Apr 2004
Distribution: Mandrake
Posts: 28

Original Poster
Rep: Reputation: 15
I've managed to solve the problem using a symbolic link from /var/lib/mysql/mysql.sock to /tmp/mysql.sock

Would prefer to know what the 'correct' solution is though.

Cheers
 
Old 06-16-2004, 06:42 AM   #7
barrys
Member
 
Registered: Sep 2003
Location: London
Distribution: Susi 9.1, Man10 amd64, Man10.1
Posts: 243

Rep: Reputation: 30
Did you not run the mysql rpm from 10.

you appear to have the standard redhat configuration location of the sock.?

Perhaps, you downloaded an new mysql?
 
Old 06-17-2004, 02:44 AM   #8
sy-co
LQ Newbie
 
Registered: Apr 2004
Distribution: Mandrake
Posts: 28

Original Poster
Rep: Reputation: 15
yep Barrys plz check the first entry, first line of this thread. Cheers.
 
Old 06-18-2004, 08:26 AM   #9
MunterMan
Member
 
Registered: Nov 2003
Location: The North of England
Distribution: Suse 10.3
Posts: 172

Rep: Reputation: 30
RTFM

A.4.5 How to Protect or Change the MySQL Socket file /tmp/mysql.sock

The manual, if you don't have it is downloadable or online.
The chapter you want is:

http://dev.mysql.com/doc/mysql/en/Pr...ysql.sock.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bugzilla - MySQL - perl - DBD::mysql install problem Runningonair Linux - Software 8 10-12-2007 12:42 AM
Problem with my internet conection oosswwaalldd Linux - Networking 2 08-28-2005 02:43 AM
mandrake 10 internet conection problem. Please Help thtr2k Linux - Wireless Networking 2 03-19-2005 05:04 PM
sharing conection (iptables) problem TiCkO Slackware 1 01-13-2005 02:30 PM
3Com-C905Tx Solaris conection problem nemesis2 Solaris / OpenSolaris 4 10-13-2003 01:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 04:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration