Page 1 of 1

How to specify the MySQL port?

Posted: Thu Mar 29, 2007 2:25 am
by Pedahzur
We run our MySQL 5 server on a non standard port due to a parallel install of MySQL 4 (migration in process). Thus, the database server I want is not on port 3306. But when I specify db.host.com:3307, I get this message back:

Unknown MySQL server host 'db.host.com:3307'

I'm doing expert install, and there is no Mysql port option in the database options. And from looking through functions_installer.inc.php, it seems that S9y doesn't even support that option at all.

How can I get around this?

Thanks!

Re: How to specify the MySQL port?

Posted: Thu Mar 29, 2007 10:44 am
by garvinhicking
Hi!

Which PHP version and mysql client library are you using?

Entering the DBhost as "db.host.com:3307" should work. If you are running a DB server on db.host.com and it works there when you enter "db.host.com" try to enter "db.host.com:3306" to see if it generally works.

It might be your mysql server is only running using Sockets and not ports, and thus the connection fails.

According to the docs on mysql_connect() on www.php.net, specifying the port after the hostname is correct. If you are running an old PHP version or old MySQL client libs this might be different for you.

Best regards,
Garvin

Re: How to specify the MySQL port?

Posted: Thu Mar 29, 2007 7:26 pm
by Pedahzur
garvinhicking wrote:Hi!
Which PHP version and mysql client library are you using?
php5 -v
PHP 5.1.2 (cli) (built: Mar 7 2007 21:53:56)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

apt-cache show php5-mysqli
Package: php5-mysqli
Priority: optional
Section: web
Installed-Size: 160
Maintainer: Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>
Architecture: i386
Source: php5
Version: 5.1.2-1ubuntu3.6
garvinhicking wrote: Entering the DBhost as "db.host.com:3307" should work. If you are running a DB server on db.host.com and it works there when you enter "db.host.com" try to enter "db.host.com:3306" to see if it generally works.

It might be your mysql server is only running using Sockets and not ports, and thus the connection fails.

According to the docs on mysql_connect() on www.php.net, specifying the port after the hostname is correct. If you are running an old PHP version or old MySQL client libs this might be different for you.
It would seem that way, but apparently when that host/port string is being passed to the driver, it's not seeing it as two separate things, because this is the error I get back on the admin page:

Code: Select all

Could not connect to database; check your settings.
The mySQL error was: Unknown MySQL server host 'db.host.com:3307' (1)
It's not a "can't connect" message, it can't even find the server. If I take out the ":3307" it comes back with it an access denied message because it hits the MySQL 4 serer which doesn't have the s9y user.

According to the mysqli docs, the host and port are two separate entities:
Procedural style
mysqli mysqli_connect ( [string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket]]]]]] )
Object oriented style (constructor):
class mysqli {
__construct ( [string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket]]]]]] )
}
port
Specifies the port number to attempt to connect to the MySQL server.
In the mysql extension, the port number can be part of host name. So, I guess my "problem" is that I was trying to use the mysqli extension, and s9y isn't coded to use a custom port when using mysqli. I guess I'll use the mysql extension. I didn't assume there would be any difference either, so in my original post, I never wrote about the fact that I was using mysqli. Sorry if that created unnecessary confusion.

Re: How to specify the MySQL port?

Posted: Fri Mar 30, 2007 12:03 pm
by garvinhicking
Hi!

Ah, mysqli was the clue. :)

I committed this patch, maybe you can try it:

http://svn.berlios.de/viewcvs/serendipi ... 47&r2=1659

HTH,
Garvin

Re: How to specify the MySQL port?

Posted: Tue Apr 03, 2007 2:42 am
by Pedahzur
garvinhicking wrote:Ah, mysqli was the clue. :)

I committed this patch, maybe you can try it:

http://svn.berlios.de/viewcvs/serendipi ... 47&r2=1659
I replaced that file, changed my config to MySQLi, my config_local says I'm using mysqli, and all seems to be working well.

Thanks for the quick fix!

j