简体   繁体   English

在 Windows 10 上使用 MAMP 无法连接到“本地主机”(10061)(2003)错误 phpmyadmin 上的 MySQL 服务器

[英]Can't connect to MySQL server on 'localhost' (10061) (2003) error phpmyadmin using MAMP on windows 10

I am trying to create a database for a PHP project using MySQL in phpmyadmin and also using MAMP on windows 10 and after I create the database and create a new user and try to check the database connection..it shows the below error..我正在尝试在 phpmyadmin 中使用 MySQL 为 PHP 项目创建数据库,并在 Windows 10 上使用 MAMP,在我创建数据库并创建新用户并尝试检查数据库连接之后..它显示以下错误..

Database connection failed: Can't connect to MySQL server on 'localhost' (10061) (2003)数据库连接失败:无法连接到“本地主机”上的 MySQL 服务器 (10061) (2003)

I did check relevant questions in the forums and tried all the tricks there but did not work..我确实在论坛中检查了相关问题并尝试了那里的所有技巧,但没有奏效。

I am mostly a Wordpress developer and I am able to create a new database in wordpress like before but PHP is giving me issues..我主要是一名 Wordpress 开发人员,我能够像以前一样在 wordpress 中创建一个新数据库,但 PHP 给我带来了问题..

Please check my codes..请检查我的代码..

config.php配置文件

 <?php

    // Database Constants
    defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
    defined('DB_USER')   ? null : define("DB_USER", "pop234");
    defined('DB_PASS')   ? null : define("DB_PASS", "4JfQuuQnzU6yfPdm");
    defined('DB_NAME')   ? null : define("DB_NAME", "demo");

    ?>

database.php数据库.php

<?php

    require_once ('config.php');

    class MYSQLDatabase {

        private $connection;

      function __construct() {
        $this->open_connection();
      }

      public function open_connection() {
        $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
        if(mysqli_connect_errno()) {
          die("Database connection failed: " . 
               mysqli_connect_error() . 
               " (" . mysqli_connect_errno() . ")"
          );
        }
      }
    }

    $database = new MySQLDatabase();
    $db =& $database;

    ?>

index.php索引.php

<?php

require_once('../includes/database.php');

if(isset($database)) { echo "true"; } else { echo "false"; }
echo "<br />";

?>

I have also tried using 127.0.0.1:8889 instead of localhost like i do in my WP programs if I get a database error..如果出现数据库错误,我也尝试过使用 127.0.0.1:8889 而不是 localhost,就像我在 WP 程序中所做的那样。

Please assist and advise请协助和建议

Thanking you in anticipation..感谢你在期待..

<?php

// PHP Database Constants
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER')   ? null : define("DB_USER", "popat234");
defined('DB_PASS')   ? null : define("DB_PASS", "4JfQuuQnzU6yfPdm");
defined('DB_NAME')   ? null : define("DB_NAME", "demo");

// Wordprsss Database Constants
/** The name of the database for WordPress */
define('DB_NAME', 'demo');

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

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

/** MySQL hostname */
define('DB_HOST', '127.0.0.1:8889');

?>

The DB_USER is different in the two configurations. DB_USER在这两种配置中是不同的。 config.php shows 'pop234' and wp-config.php uses 'popat234' which is apparently the correct one. config.php显示“pop234”, wp-config.php使用“popat234”,这显然是正确的。

Make sure that your config.php contains:确保您的config.php包含:

 <?php

    // Database Constants
    defined('DB_SERVER') ? null : define("DB_SERVER", "127.0.0.1");
    defined('DB_PORT') ? null : define("DB_PORT", "8889");
    defined('DB_USER')   ? null : define("DB_USER", "popat234");
    defined('DB_PASS')   ? null : define("DB_PASS", "4JfQuuQnzU6yfPdm");
    defined('DB_NAME')   ? null : define("DB_NAME", "demo");

Also correct your mysqli_connect() line to:还要将您的mysqli_connect()行更正为:

    $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME, DB_PORT);

try to switch your port from 8889 to 3306, this resolve my problem.尝试将您的端口从 8889 切换到 3306,这解决了我的问题。 This maybe can occurr because the Windows block the port 8889.这可能是因为 Windows 阻止了端口 8889。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 #2003-无法连接到“本地主机”上的MySQL服务器(10061) - #2003 - Can't connect to MySQL server on 'localhost' (10061) 错误2003(HY000):无法连接到“本地主机”上的MySQL服务器(10061“未知错误”) - ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061 “Unknown error”) MAMP 无法连接到本地主机上的 MySQL (10061) - 2017 - MAMP Unable to Connect to MySQL on localhost (10061) - 2017 运行MySQL的帮助。 SQL yog给出错误HY000):无法连接到“本地主机”上的MySQL服务器(10061) - Help in Running MySQL. SQL yog gives error HY000): Can't connect to MySQL server on 'localhost' (10061) 无法连接到IPAddress上的MySQL Server(10061) - Can't Connect to MySQL Server on IPAddress (10061) 错误2003(HY000)无法连接到本地主机上的mysql服务器 - ERROR 2003 (HY000) cant connect to mysql server on localhost 无法使用MAMP通过localhost建立与MySQL的连接 - Can't establish connect to MySQL over localhost with MAMP 无法使用MAMP服务器连接到phpMyAdmin数据库 - Cannot connect to phpMyAdmin database using MAMP Server 无法连接到 phpMyAdmin 或 localhost - Can't connect to phpMyAdmin or localhost 无法使用 phpMyAdmin 连接到 mySQL 服务器中的数据库 - Can not connect to database in mySQL server using phpMyAdmin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM