【问题标题】:Can't connect to MySQL server on 'aetos.it.teithe.gr' (111)无法连接到“aetos.it.teithe.gr”上的 MySQL 服务器 (111)
【发布时间】:2016-01-11 12:24:56
【问题描述】:

我想连接到我技术学院的mysql服务器.. 我的 php 文件 db_config.php

<?php
 /*
 All Database connection variables
 */
define("DB_SERVER", "aetos.it.teithe.gr");
define("DB_DATABASE", "votingdb");
define("DB_USER", "root@localhost");
define("DB_PASSWORD", "..");

?> 

db_connect.php

   <?php

  /*
 A class file to connect to database
 */
 class DB_CONNECT{

  /*
  function to connect with database
  */
  function connect(){
   //import database connection variables
   require_once __DIR__ . "/db_config.php";

   //connecting to mysql database
   $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or    die (mysqli_connect_errno() . PHP_EOL);

//returning connection cursor
if (!is_null($con)){
    return $con;
   }
  }

}

test_connection.php

<?php

  /*
    get firm(table) from votingdb database details(firm_name, email, ...)
  */

//array for json response
$response = array();

//include db_connect class
require_once __DIR__ . "/db_connect.php";

 //initialise DB_CONNECT class
 $db_connect = new DB_CONNECT();

 //get $link for the db connection link
 $link = $db_connect->connect();

 //get firm_name field from firm table
 $result = mysqli_query($link, "SELECT firm_name, city FROM Firm");

 if (!empty($result)){
   echo nl2br("firm has " . mysqli_num_rows($result) . " firms\n");

  $response["firms"] = array();

  while ($row = mysqli_fetch_array($result)){
    //temp user array
    $firm = array();
    $firm["firm name"] = $row["firm_name"];
    $firm["firm city"] = $row["city"];

    //push single product into final response array
    array_push($response["firms"], $firm);
  }

  //success
  $response["success"] = 1;

  //echo json response
  echo json_encode($response, JSON_PRETTY_PRINT);

  //free result set
  mysqli_free_result($result);
  //close connection
  mysqli_close($link);
}
 else {
  $response["success"] = 0;
  $response["message"] = "No firms found";

   echo json_encode($response, JSON_PRETTY_PRINT);
  }


 ?>

当我运行 test_connection.php 时出现以下错误...警告:mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'aetos.it.teithe.gr' (111) in /home/student/x0809/tsironis/public_html/Ptixiaki/db_connect.php 2003 年第 16 行 谁能解释我做错了什么?

我还添加了 my.cnf 文件

   [client]
   socket=/home/student/x0809/tsironis/mysql/run/mysql.sock

   [mysqld_safe]
   socket=/home/student/x0809/tsironis/mysql/run/mysql.sock

   [mysqld]
   socket=/home/student/x0809/tsironis/mysql/run/mysql.sock
   pid-file=/home/student/x0809/tsironis/mysql/run/mysql.pid
   log=/dev/null
   log-error=//home/student/x0809/tsironis/mysql/log/mysql.log
   log_bin=/home/student/x0809/tsironis/mysql/log/mysql-bin.log
   datadir=/home/student/x0809/tsironis/mysql/data
   tmpdir=/home/student/x0809/tsironis/mysql/tmp

  max_binlog_size=10M
  skip-networking

【问题讨论】:

  • 我看到的第一件事就是用户错误未定义(“DB_USER”,“root@localhost”);只定义("DB_USER", "root");
  • 第二个是:看起来数据库在3306端口上没有到达。是否有防火墙或在my.cnf中绑定地址是localhost。将其更改为 0.0.0.0
  • 还是一样..我也改变了服务器的路径...("DB_SERVER", "aetos.it.teithe.gr/home/student/x0809/tsironis/mysql/run/ mysql.sock");

标签: mysql


【解决方案1】:

对不起,这不是答案,但我无法格式化, 我已经从这里检查了港口。端口 3306 未打开,因此您无法访问数据库。所以你只能通过 ssh 上的隧道来获取它

$ nmap aetos.it.teithe.gr

Starting Nmap 5.20 ( http://nmap.org ) at 2015-10-13 19:14 CEST
Nmap scan report for aetos.it.teithe.gr (195.251.123.232)
Host is up (0.083s latency).
Not shown: 985 closed ports
PORT     STATE    SERVICE
22/tcp   open     ssh
53/tcp   open     domain
80/tcp   open     http
110/tcp  open     pop3
135/tcp  filtered msrpc
139/tcp  filtered netbios-ssn
143/tcp  open     imap
443/tcp  open     https
445/tcp  filtered microsoft-ds
993/tcp  open     imaps
995/tcp  open     pop3s
4444/tcp filtered krb524
5432/tcp open     postgresql
6667/tcp open     irc
6969/tcp open     acmsoda

【讨论】:

  • 我对这一切都非常陌生...您能详细描述一下我如何通过 ssh 上的隧道获取它..
  • 简短的问题:你在你的数据库服务器和客户端服务器上使用 linux
  • sh....,Windows 不是我最喜欢的系统,但我找到了一个描述 mysql 的页面 dev.mysql.com/doc/refman/5.0/en/windows-and-ssh.html 如果有帮助,现在让我来
  • 唯一的事情是:使用 ssh,您可以与远程服务器 (DB) 建立安全连接,然后您可以转发本地端口。所以可以连接到本地主机,即。端口 3307,它直接连接到远程机器的端口 3306 (DB),您可以以本地用户身份连接。那么它就和你在 db db 机器上直接连接一样
  • 最后...Bernd Buffen 我要建立的不是与 mysql 服务器的远程连接...我当前的工作目录位于同一台服务器内...任何其他可能的建议错了吗?
猜你喜欢
  • 2016-12-19
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 2015-08-26
  • 1970-01-01
  • 2014-05-10
  • 2010-12-13
  • 2018-01-31
相关资源
最近更新 更多