Failed to connect to MySQL server on: 127.0.0.1

General discussion about netjukebox
Locked
der_mythos
User
Posts: 3
Joined: Sat Dec 22, 2012 7:34 pm

Failed to connect to MySQL server on: 127.0.0.1

Post 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
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Re: Failed to connect to MySQL server on: 127.0.0.1

Post 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????
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Re: Failed to connect to MySQL server on: 127.0.0.1

Post 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 :)
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Re: Failed to connect to MySQL server on: 127.0.0.1

Post 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']);
Locked