Page 1 of 1

Failed to connect to MySQL server on: 127.0.0.1

Posted: Sat Dec 22, 2012 7:39 pm
by der_mythos
Hi,

I am trying to setup netjukebox on my PogoPlug with ArchLinux running. Everything went quite fine till I get this message: Failed to connect to MySQL server on:
127.0.0.1.

I setup the config.ini like this:

$cfg['mysqli_host'] = '127.0.0.1';
$cfg['mysqli_db'] = 'netjukebox';
$cfg['mysqli_user'] = 'root';
$cfg['mysqli_password'] = 'myPassword';
$cfg['mysqli_port'] = '3306';
//$cfg['mysqli_socket'] = '/var/run/mysqld/mysqld.sock'; <---- Outcommented this one because I found someone mentioning this in another thread - however didn't changed anything
$cfg['mysqli_auto_create_db'] = true;

I can connect to my MySql server on Commandline like this: mysql -u root -p myPassword.

What am I missing out?

Best regards Robin

Re: Failed to connect to MySQL server on: 127.0.0.1

Posted: Sat Dec 22, 2012 11:31 pm
by wbartels
Do not comment out any line!
Leave out the port number, on my Ubuntu system it wont connect with a port number.
I have tried the port number as a string and as a integer but now luck.

Try this:

Code: Select all

$cfg['mysqli_host'] = '127.0.0.1';
$cfg['mysqli_db'] = 'netjukebox';
$cfg['mysqli_user'] = 'root';
$cfg['mysqli_password'] = 'myPassword';
$cfg['mysqli_port'] = '';
$cfg['mysqli_socket'] = '';
$cfg['mysqli_auto_create_db'] = true;
The PHP manual says that it should work with a port number but somehow it doesn't work

Code: Select all

mysqli_connect ([ string $host = ini_get("mysqli.default_host") [, string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
This is the code I use to connect

Code: Select all

//  +------------------------------------------------------------------------+
//  | mysqli.inc.php                                                         |
//  +------------------------------------------------------------------------+
$db = @mysqli_connect(
	$cfg['mysqli_host'],
	$cfg['mysqli_user'],
	$cfg['mysqli_password'],
	($cfg['mysqli_port'] == '') ? null : $cfg['mysqli_port'],
	($cfg['mysqli_socket'] == '') ? null : $cfg['mysqli_socket']
) or message(__FILE__, __LINE__, 'error', '[b]Failed to connect to MySQL server on:[/b][br]' . $cfg['mysqli_host']);
Does anyone know how to fix this????

Re: Failed to connect to MySQL server on: 127.0.0.1

Posted: Sun Dec 23, 2012 10:03 am
by wbartels
Hello I split this topic and lost this reply from der_mythos, sorry!
Wow, thank you very much. This worked like a charm to me!!!

However I can't tell you why setting ports doesn't work. My first thought would be, that setting a port to localhost is not a good idea an therefore, php said, we don't allow ports on localhost. But thats really a spontaneous idea. As a workaround, maybe skip the port on localhost.

Thank you :)

Re: Failed to connect to MySQL server on: 127.0.0.1

Posted: Sun Dec 23, 2012 2:28 pm
by wbartels
wbartels wrote:Does anyone know how to fix this????
Oops, I forgot the dbname before port :oops:
I will fix this in netjukebox 5.38.4 than port number can be used again!

Here is a the fix:

Code: Select all

//  +------------------------------------------------------------------------+
//  | mysqli.inc.php                                                         |
//  +------------------------------------------------------------------------+
$db = @mysqli_connect(
	$cfg['mysqli_host'],
	$cfg['mysqli_user'],
	$cfg['mysqli_password'],
	null,
	($cfg['mysqli_port'] == '') ? null : $cfg['mysqli_port'],
	($cfg['mysqli_socket'] == '') ? null : $cfg['mysqli_socket']
) or message(__FILE__, __LINE__, 'error', '[b]Failed to connect to MySQL server on:[/b][br]' . $cfg['mysqli_host']);