简体   繁体   English

连接被拒绝,无法连接到 XAMPP 上的单独 MySQL

[英]Connection refused, trouble connecting to separate MySQL on XAMPP

I'm having issues getting a MySQL connection in PHP using XAMPP and a separate local MySQL server (not the included MariaDB that myphpadmin is running). I'm having issues getting a MySQL connection in PHP using XAMPP and a separate local MySQL server (not the included MariaDB that myphpadmin is running).

I've installed MySQL on my computer separately (as I can't run MariaDB due to work reasons), it works fine in terminal and in MyWorkBench.我已经在我的计算机上单独安装了 MySQL(由于工作原因,我无法运行 MariaDB),它在终端和 MyWorkBench 中运行良好。 I've updated the port to 3307 to mitigate the risk of it potentially running on the same port as MariaBD (which I have confirmed is actually not running in terminal).我已将端口更新为 3307,以降低它可能在与 MariaBD 相同的端口上运行的风险(我已经确认它实际上并未在终端中运行)。

My credentials are correct (as they work in terminal).我的凭据是正确的(因为它们在终端中工作)。

$dbobj = new PDO("mysql:host=$dbhost;dbname=$dbdatabase;charset=utf8;port=3307", $dbuser, $dbpwd);

If I try and connect using localhost I get this error: SQLSTATE[HY000] [2002] No such file or directory如果我尝试使用 localhost 进行连接,则会收到此错误: SQLSTATE[HY000] [2002] No such file or directory

If I try and connect using ip 127.0.0.1 I get this error: SQLSTATE[HY000] [2002] Connection refused如果我尝试使用 ip 127.0.0.1 进行连接,我会收到此错误:SQLSTATE[HY000] [2002] Connection denied

Both using port 3307, both work in terminal.两者都使用端口 3307,都在终端中工作。

Running XAMPP v. 7.3.10-0, MySQL: 5.7, macOS Catalina 10.15运行 XAMPP v. 7.3.10-0,MySQL:5.7,macOS Catalina 10.15

I'll answer my own question incase someone runs into the same issue.如果有人遇到同样的问题,我会回答我自己的问题。 I had someone experienced look into this and due to the new XAMPP being run on a virtual machine there is no good solution to my problem.我曾有人对此进行过调查,由于新的 XAMPP 在虚拟机上运行,因此我的问题没有好的解决方案。 Install MySQL directly on the VM will be too time consuming as it won't have all packages needed etc. So best solution is to either see if work can let me use Maria DB in the interim, or use a different PHP server solution.直接在虚拟机上安装 MySQL 会太费时间,因为它没有所需的所有软件包等。所以最好的解决方案是看看工作是否可以让我在此期间使用 Maria DB,或者使用不同的 PHP 服务器解决方案。

As far as I understand you have installed on the same mac box MariaDB and a virtual machine in with you have installed XAMPP.据我了解,您已经在同一个 Mac 机器上安装了 MariaDB,并且与您一起安装的虚拟机已经安装了 XAMPP。 And you tried to make a connection between something running in the VM and something running outside on localhost.你试图在虚拟机中运行的东西和在本地主机上运行的东西之间建立联系。

There is something called nmap also for macOS, https://nmap.org/book/inst-macosx.html and you can use it to scan your box and see what services you have on it. macOS 也有一个叫做 nmap 的东西, https://nmap.org/book/inst-macosx.html ,你可以用它来扫描你的盒子,看看你有什么服务。 Using nmap you could have seen that your not on the same environment.使用 nmap 您可能已经看到您不在同一个环境中。 (?! ) (?!)

Anyway I found here some guy telling a very similar story.无论如何,我在这里找到了一些人讲了一个非常相似的故事。 It looks like he was able to connect the VM with the localhost and it took him a minute.看起来他能够将 VM 与 localhost 连接起来,这花了他一分钟时间。

The next guy is telling about how to access your service on the host machine in your case the database by the hostname setting the network to bridge.下一个人正在讲述如何通过将网络设置为桥接的主机名来访问主机上的服务。 < <

On macOS you have ifconfig like on Linux, on windows it is called ipconfig, that gives you all information about all adapters you have and the different ip addresses在 macOS 上,您有 ifconfig,例如 Linux,在 windows 上,它称为 ipconfig,它为您提供有关您拥有的所有适配器和不同 ip 地址的所有信息

root@tux:~# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.178.33  netmask 255.255.255.0  broadcast 192.168.178.255
        inet6 fe80::42a8:f0ff:fea2:1e58  prefixlen 64  scopeid 0x20<link>
        ether 40:a8:f0:a2:1e:58  txqueuelen 1000  (Ethernet)
        RX packets 366455797  bytes 41401605218 (38.5 GiB)
        RX errors 0  dropped 65936  overruns 0  frame 0
        TX packets 745920997  bytes 846447546164 (788.3 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf7c00000-f7c20000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Lokale Schleife)
        RX packets 6945633  bytes 1073031154 (1023.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6945633  bytes 1073031154 (1023.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

But you are right better ask the work to accept... something.但你是对的,最好让工作接受……一些东西。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM