dtqysxw4659 2016-08-25 09:48
浏览 269
已采纳

在Mac上的XAMPP中连接到MySQL数据库

I am using cakePHP to connect to a database in XAMPP phpMyAdmin. I have added a new user, set the password and set the privilleges. I cannot for the life me create a connection to the database on my localhost. What I have done so far.... I have a live web server with a database. I can connect to this database no problem. I have a database running in MySQL workbench on localhost. I can connect to this no problem. This tells me that there is nothing wrong with my connection code and the problem must sit with phpMyAdmin in XAMPP. I have created a simple connection PHP script to try and connect to the database and it doesn't work. The same script can connect to my live web server and my localhost MySQL workbench database but not my XAMPP database. My connection script is as follows:

<?php

   $con= mysqli_connect("localhost","root","","test");
   // Check connection
   if (mysqli_connect_errno())
   {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

   // Perform a query, check for error
   if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')"))
   {
        echo("Error description: " . mysqli_error($con));
   }

   mysqli_close($con);

?>

The error message I get is;

Failed to connect to MySQL: Access denied for user 'root'@'localhost' (using password: NO)Error description:

If i go to phpMyAdmin in XAMPP and go to the test database I can clearly see that this user has full access. I have tried using the host name as 127.0.0.1, localhost and ::1. Nothing seems to work. I just dont understand why XAMPP will not let me connect to the database. I hope I'm not missing something obvious so any help will really be appreciated. here is a screen shot of the users and their privilleges for the database test

展开全部

  • 写回答

3条回答 默认 最新

  • duandai3964 2016-08-25 11:45
    关注

    That's the second reason why one should never use 'root' unless one knows exactly what one is doing. Only a few expirenced ones really know what they're doing each and every moment...

    Add a specific useraccount like 'data' on your localhost and grant it the needed priviledges on your DB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 RHEL8.10安装文件
  • ¥25 实时时钟,测温,模拟量采集,超声波测距,四种在数码管上的显示通过独立按键S4依次切换
  • ¥50 Linq更新数据导致数据库崩溃
  • ¥15 使用vue3+springboot+elementplus开发web小项目,用easyexcel导出后台查询到的数据。postman测试下载测试成功但是浏览器不能触发下载
  • ¥15 关于#r语言#的问题:单细胞数据处理
  • ¥15 我主页资源的代码要如何导入JAVAEE里面使其可以运行
  • ¥20 如何在linux centos7中,搭建DVWA?
  • ¥20 更改手机应用的音频输入/推荐其他方案
  • ¥15 数据库 'LibraryManage' 已存在。请选择其他数据库名称。
  • ¥20 windows毛玻璃窗口缩放延时问题