LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Mandriva (https://www.linuxquestions.org/questions/mandriva-30/)
-   -   mysql conection problem (https://www.linuxquestions.org/questions/mandriva-30/mysql-conection-problem-193724/)

sy-co 06-15-2004 06:45 AM

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

linuxxed 06-15-2004 07:27 AM

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)

MunterMan 06-15-2004 08:18 AM

Try it without the password. eg

mysql_connect ("localhost", "username");

barrys 06-15-2004 11:17 AM

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

sy-co 06-15-2004 09:48 PM

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

sy-co 06-15-2004 10:08 PM

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

barrys 06-16-2004 06:42 AM

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?

sy-co 06-17-2004 02:44 AM

yep Barrys plz check the first entry, first line of this thread. Cheers.

MunterMan 06-18-2004 08:26 AM

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


All times are GMT -5. The time now is 04:50 PM.