php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61570 mysqlnd cannot connect to MySQL when named pipe is used with open_basedir
Submitted: 2012-03-30 16:23 UTC Modified: 2020-12-13 21:32 UTC
Votes:11
Avg. Score:3.8 ± 1.3
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:5 (62.5%)
From: peaceable_whale at hotmail dot com Assigned:
Status: Open Package: MySQLi related
PHP Version: 5.4.1 OS: Windows Server 2008 R2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: peaceable_whale at hotmail dot com
New email:
PHP Version: OS:

 

 [2012-03-30 16:23 UTC] peaceable_whale at hotmail dot com
Description:
------------
Although the bug, according to https://bugs.php.net/bug.php?id=48082, should have been fixed in PHP 5.4.x, connection to MySQL via named pipe remains unsuccessful. 5.4.0 and 5.4.1 have the same issue.

Test script:
---------------
1. Set the MySQL server to use Named Pipe only
2. Connect to it using mysqlnd (mysql or mysqli)


Expected result:
----------------
Connection established

Actual result:
--------------
Connection failed

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-24 20:27 UTC] andrey@php.net
-Status: Open +Status: Feedback
 [2012-04-24 20:27 UTC] andrey@php.net
Please paste a snippet that shows it doesn't work.
Thanks!
 [2012-04-25 02:33 UTC] peaceable_whale at hotmail dot com
The script used for testing is as follows:

<?php
$db=new mysqli("localhost", "root", PASSWORD);
if($db->connect_errno !== 0) {
	exit("Unable to connect to database: ".$db->connect_error);
}
echo "Connected";
$db->close();
?>

Result:

Warning: mysqli::mysqli(): (HY000/2002): No connection could be made because the target machine actively refused it.
Unable to connect to database: No connection could be made because the target machine actively refused it.

Remarks:

The database has enable-named-pipe and skip-networking in effect.
 [2012-04-25 02:33 UTC] peaceable_whale at hotmail dot com
-Status: Feedback +Status: Open
 [2012-04-25 19:52 UTC] andrey@php.net
I don't want to be rude. Please read, the MySQL documentation. When you want to use named pipes your host should not be "localhost". "localhost" has a special meaning only on Unix(-like) systems, where it means "use unix socket file", while on windows it will be resolved as 127.0.0.1 and TCP connection will be tried to be established.

On Windows, to use named pipes, you should use "." (dot) as host, which will in turn use the default named pipe name \\.\pipe\MySQL (if you use the name in your code you should escape the slashes, if you use double quotes "\\\\.\\pipe\\MySQL".
Please try this and report your success or failure.
 [2012-04-26 03:33 UTC] peaceable_whale at hotmail dot com
When using "." as the hostname, the following warning is returned:

Warning: mysqli::mysqli(): (HY000/2002): Unknown errror while connecting

When using "\\\\.\\pipe\\MySQL". as the hostname, the following error is returned:

php_network_getaddresses: getaddrinfo failed: No such host is known.

Regarding documentation, if "." is required for named pipe connection, the PHP documentation, not the MySQL documentation, should explicitly state so. Currently, it only states "Can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.", I expected that passing "localhost" will cause pipes to be used when possible, and did not expect "." is supported as it is not a valid hostname or IP address.
 [2012-05-03 08:33 UTC] peaceable_whale at hotmail dot com
-PHP Version: 5.4.1RC1 +PHP Version: 5.4.1
 [2012-05-03 08:33 UTC] peaceable_whale at hotmail dot com
Changed affected PHP version to 5.4.1.
 [2012-05-04 08:45 UTC] uw@php.net
Can you connect to MySQL using named pipe and the mysql prompt (http://dev.mysql.com/doc/refman/5.5/en/connecting.html)?
 [2012-05-04 08:45 UTC] uw@php.net
-Status: Open +Status: Feedback
 [2012-05-04 08:49 UTC] peaceable_whale at hotmail dot com
-Status: Feedback +Status: Open
 [2012-05-04 08:49 UTC] peaceable_whale at hotmail dot com
Yes, I am able to connect using the following command:

mysql -W -u root -p
 [2012-05-04 10:18 UTC] peaceable_whale at hotmail dot com
-Type: Bug +Type: Documentation Problem
 [2012-05-04 10:18 UTC] peaceable_whale at hotmail dot com
Finally, I found that the connection problem is caused by the use of open_basedir. It appears that named pipe cannot be used with open_basedir.

I have changed the type of this report to be documentation problem. I think the documentation should mention that:

- "." should be used instead of "localhost" for named pipe connection
- Named pipe will fail when open_basedir is in effect
 [2012-06-14 12:12 UTC] uw@php.net
Thanks for following up and changing to doc problem. Great hint on open basedir... mysqlnd is using PHP Streams and PHP Stream will follow PHP rules.
 [2014-11-20 03:04 UTC] o dot g dot 67 at mail dot ru
I have this problev when <mysqli.default_socket="mysql"> and use msqli.
To solve need cleanup this parameter <mysqli.default_socket=>
 [2014-11-20 03:31 UTC] o dot g dot 67 at mail dot ru
sorry, "this problem" :)
change need make in file <php.ini>
 [2014-11-20 11:14 UTC] o dot g dot 67 at mail dot ru
====more complete instructions to solve this problem on windows platform====
============================================================================
in file <php.ini>, or another config php files if use, need follower:

mysql.default_socket=
mysqli.default_socket=


in file <my.ini>, or another config mysql files if use, need follower:

socket = mysql
============================================================================
It's all :)
 [2017-04-02 14:44 UTC] tpunt@php.net
-Package: mysql +Package: MySQLi related
 [2020-12-13 21:32 UTC] dharman@php.net
-Summary: mysqlnd cannot connect to MySQL when only named pipe is enabled +Summary: mysqlnd cannot connect to MySQL when named pipe is used with open_basedir
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC