Php 远程mysql连接错误为(HY000/1130)

Php 远程mysql连接错误为(HY000/1130),php,mysql,database,connect,remote-access,Php,Mysql,Database,Connect,Remote Access,我想用php连接远程mysql数据库,但出现了错误 我的错在哪里?我怎样才能解决它? 我的php代码如下: <?php $servername = "mysql.somedomain.com"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if

我想用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";
?>

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

你需要像这样做

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'; 
在服务器上,从具有相应权限的用户(例如root用户)处获取信息。

通过以下方式进行检查:

  • 打开本地主机控制面板
  • 配置(在apache字段中)
  • 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控制面板,然后重试。
    然后启动本地主机并使用。

    希望您的错误不是您向世界提供了真实的数据库凭据…(尽管我无法想象您的密码是
    12345
    :D)错误消息似乎非常清楚。不允许您使用当前用户名和远程主机的组合连接到该数据库服务器。@Rasclatt,我的行李上也有相同的密码:-)你可能会想更改你的用户名和密码,因为你的凭证现在正在编辑你的帖子,所以即使@MikeBrant编辑了你的帖子,任何人都可以进入你的数据库。Thnks@Iserni我可以在哪里做?cmd或cpanel?我如何用cpanel制作它们?我不熟悉cpanel。您需要一些服务器端可以与mysql对话的东西。如果您有一个shell,那么可以使用mysql cmdline客户端。或phpMyAdmin(如果已安装)。
    /* 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.