【问题标题】:remote mysql connection error is (HY000/1130)远程mysql连接错误是(HY000/1130)
【发布时间】:2015-01-19 22:38:52
【问题描述】:

我想用 php 连接远程 mysql 数据库,但出现错误。

我的错误在哪里?我该如何解决?

我的 php 代码在这里:

<?php
$servername = "mysql.somedomain.com";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

【问题讨论】:

  • 希望你的错误不是你向世界提供了你真正的数据库凭据......(虽然我无法想象你的密码会是12345 :D)
  • 错误信息似乎很清楚。不允许您使用当前的用户名和远程主机组合连接到该数据库服务器。
  • @Rasclatt,我的行李箱里有同样的组合 :-)
  • 好吧,您可能会想要更改您的用户名和密码,因为您的凭据现在正在编辑您的帖子,因此即使@MikeBrant 编辑了您的帖子,任何人都可以进入您的数据库。

标签: php mysql database connect remote-access


【解决方案1】:

必须授权主机连接到服务器。

你需要运行类似的东西

GRANT ALL ON *.* to u478628312_database@'88.254.234.215' IDENTIFIED BY '12345'; 

...或者更好,

GRANT <the minimum required privileges> ON yourdatabase.* to u478628312_database@'88.254.234.215' IDENTIFIED BY '12345'; 

紧随其后

FLUSH PRIVILEGES;

在服务器上,来自具有相应权限的用户(例如 root)。

【讨论】:

  • 谢谢@Iserni 我在哪里可以做? cmd 还是 cpanel ?如何在 cPanel 中制作它们
  • 我对 cPanel 不熟悉。您需要可以与mysql对话的服务器端。如果你有 shell,你可以使用 mysql cmdline 客户端。或者 phpMyAdmin 如果你安装了它。
【解决方案2】:

这样检查:

  1. 打开本地主机控制面板
  2. 配置(在 apache 字段中)
  3. phpMyAdmin (config.inc.php)

你应该有这样一段:

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

change the word 'config' with 'cookie'. then save it.

之后转到C:\xampp\mysql\backup 然后复制mysql文件夹并粘贴到C:\xampp\mysql\data

如果您看到错误,请停止 apache 和 mysql 并退出 xampp 控制面板,然后再试一次。 之后启动你的本地主机并使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2018-12-02
    相关资源
    最近更新 更多