By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

mysql_connect error Apache Web server to Windows hosted database

P: n/a
GD
Hi All,

I've got MySQL 5.0.21 running on Windows Server 2003, and php running
on Apache on a Linux box (Fedora Core 4).

Previously when the pages were running on an IIS server the connection
was succesful, now I get:

Can't connect to MySQL server on 'SERVER' (13)

I'm connecting using:

$db = mysql_connect("SERVER", "USER", "PASSWORD")
or die("Could not connect to database:
".mysql_error());
mysql_select_db("DATABASE", $db)
or die("Could not select database: ".mysql_error());

However from the linux box I can connect no problems using:
mysql --host=SERVER -u USER -p

Can anyone help point me in the right direction to solve this one?
Cheers
Dan

Jul 24 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
GD wrote:
Hi All,

I've got MySQL 5.0.21 running on Windows Server 2003, and php running
on Apache on a Linux box (Fedora Core 4).

Previously when the pages were running on an IIS server the connection
was succesful, now I get:

Can't connect to MySQL server on 'SERVER' (13)

I'm connecting using:

$db = mysql_connect("SERVER", "USER", "PASSWORD")
or die("Could not connect to database:
".mysql_error());
mysql_select_db("DATABASE", $db)
or die("Could not select database: ".mysql_error());

However from the linux box I can connect no problems using:
mysql --host=SERVER -u USER -p

Can anyone help point me in the right direction to solve this one?
Cheers
Dan
Which version of the MySQL client libraries are being used by
Apache/PHP? If it's pre-MySQL 4.1, it will use a different password
hashing algorithm.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '06 #2

P: n/a
GD

Jerry Stuckle wrote:
>
Which version of the MySQL client libraries are being used by
Apache/PHP? If it's pre-MySQL 4.1, it will use a different password
hashing algorithm.
>From phpinfo():
Active Persistent Links 0
Active Links 0
Client API version 4.1.11
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient

So this is post-MySQL 4.1?

Thanks
Dan

Jul 24 '06 #3

P: n/a
GD wrote:
Jerry Stuckle wrote:

>>Which version of the MySQL client libraries are being used by
Apache/PHP? If it's pre-MySQL 4.1, it will use a different password
hashing algorithm.

>>From phpinfo():

Active Persistent Links 0
Active Links 0
Client API version 4.1.11
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib/mysql -lmysqlclient

So this is post-MySQL 4.1?

Thanks
Dan
Yes, that's post 4.1. In that case I would check your server, userid
and password in the mysql_connect() statement very closely.

The fact you can connect from the linux box to the Windows box with
mysql command line utility indicates MySQL on the Windows box is set up
for networking OK, no firewalls in place, etc. The mysql_connect()
statement on the Linux box should use the same type of call.

The only other possibility I can think of is your command line MySQL on
the Linux box might be an older version and you're using pre-4.1
passwords on the Windows MySQL box. "mysql -V" would tell you the
version you're running on the Linux command line.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '06 #4

P: n/a
GD
Jerry Stuckle wrote:
GD wrote:
Jerry Stuckle wrote:
The only other possibility I can think of is your command line MySQL on
the Linux box might be an older version and you're using pre-4.1
passwords on the Windows MySQL box. "mysql -V" would tell you the
version you're running on the Linux command line.
Hi Jerry,

thanks for your suggestions, mysql -V reports that I'm running version:

mysql Ver 14.7 Distrib 4.1.11, for redhat-linux-gnu (i386)

so again it's post-v4.1.
I've looked at the servername, user and password and tried all
permutations, but with no success.
The only other thing I can think of is there's some sort of permissions
problem on the files, rather than the database, but I'm just clutching
at straws now. Any help very gratefully received.

Cheers
Dan

Jul 25 '06 #5

P: n/a
GD wrote:
Jerry Stuckle wrote:
>>GD wrote:
>>>Jerry Stuckle wrote:

>>The only other possibility I can think of is your command line MySQL on
the Linux box might be an older version and you're using pre-4.1
passwords on the Windows MySQL box. "mysql -V" would tell you the
version you're running on the Linux command line.


Hi Jerry,

thanks for your suggestions, mysql -V reports that I'm running version:

mysql Ver 14.7 Distrib 4.1.11, for redhat-linux-gnu (i386)

so again it's post-v4.1.
I've looked at the servername, user and password and tried all
permutations, but with no success.
The only other thing I can think of is there's some sort of permissions
problem on the files, rather than the database, but I'm just clutching
at straws now. Any help very gratefully received.

Cheers
Dan
Dan,

Hmmm, that's possible, I guess. On Linux 13 is "permission denied".
However, I would think you'd have problems even starting Apache if it
couldn't read the mysql libs.

Do you have anything in the [mysql] section of your php.ini?

Also, looking back through your first message - you indicate you get the
message:

Can't connect to MySQL server on 'SERVER' (13)

But your code puts out the messages:

"Could not connect to database: ".mysql_error();
and
"Could not select database: ".mysql_error();

Is this actually the case (your message isn't generated by your code),
or did you just mistype the message? Just want to make sure we're going
down the right path :-).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 25 '06 #6

P: n/a
GD

Jerry Stuckle wrote:
Dan,

Do you have anything in the [mysql] section of your php.ini?

Also, looking back through your first message - you indicate you get the
message:

Can't connect to MySQL server on 'SERVER' (13)

But your code puts out the messages:

"Could not connect to database: ".mysql_error();
and
"Could not select database: ".mysql_error();

Is this actually the case (your message isn't generated by your code),
or did you just mistype the message? Just want to make sure we're going
down the right path :-).
The actual message is:

Could not connect to database: Can't connect to MySQL server on
'SERVER' (13)

MySQL section of php.ini copied below.

[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 limit
mysql.connect_timeout = 60

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

Thanks for your help!
Dan

Jul 25 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.