Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
能够通过sequelpro连接到mysql,但不能通过PHP wordpress代码?_Php_Mysql_Mysqli_Mariadb - Fatal编程技术网

能够通过sequelpro连接到mysql,但不能通过PHP wordpress代码?

能够通过sequelpro连接到mysql,但不能通过PHP wordpress代码?,php,mysql,mysqli,mariadb,Php,Mysql,Mysqli,Mariadb,非常奇怪的问题 我在Mac上安装了apache、mysql等,以便在本地进行wordpress/PHP开发 mysql安装很好,这是下面的版本 mysql Ver 8.0.22 for osx10.16 on x86_64 (Homebrew) 我可以通过应用程序sequel pro连接到它,创建/管理数据库 但是,当我建立wordpress网站或通过PHP测试连接时。。我一辈子都无法和它联系起来 这是我的wordpress config.php文件的db部分: // ** MySQL s

非常奇怪的问题

我在Mac上安装了apache、mysql等,以便在本地进行wordpress/PHP开发

mysql安装很好,这是下面的版本

mysql  Ver 8.0.22 for osx10.16 on x86_64 (Homebrew)
我可以通过应用程序sequel pro连接到它,创建/管理数据库

但是,当我建立wordpress网站或通过PHP测试连接时。。我一辈子都无法和它联系起来

这是我的wordpress config.php文件的db部分:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
这是我尝试继续wordpress安装时得到的页面:

我还通过一个简单的PHP脚本进行了如下尝试:

<?php

$c = new mysqli("localhost", "root", "password", "wordpress") or die('Could not connect the database : Username or password incorrect');
echo 'Database Connected successfully';

?>
如果我将
localhost
更改为
127.0.0.1
则会出现以下错误:

Warning: mysqli::__construct(): (HY000/2002): No such file or directory
Warning: Packets out of order. Expected 0 received 1. Packet size=68 in /users/asdasda/test.php on line 3
Warning: mysqli::__construct(): MySQL server has gone away in /users/asdasda/test.php on line 3
Warning: mysqli::__construct(): Error while reading greeting packet. PID=36547 in /users/asdasda/test.php on line 3
根据


您应该避免使用localhost,而是使用IP。localhost使用IP地址127.0.0.1

好的,所以我算出了

我必须在
/etc/
中创建一个
php.ini
文件,其中包含以下行:

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock

您是如何安装apache/php的?@mikeroq使用Brewth这是一种非常糟糕的方法,因为它强制数据库通信使用TCP/IP而不是本地套接字(这将更加有效)。正确的方法是将PHP配置为指向正确的套接字文件。