简体   繁体   中英

Unable to connect to remote MySql server from all clients except php

I have remote server(windows server 2008) with MySql server installed,server has dedicated ip. I can connect on this server from remote php client using simple mysqli connection. But I cant connect from my home-PC using all other clients(MySqlWorkBench, C# etc).

To connect from C# I use:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
             {
    
                string server = "servdomain.su";
                string  database = "dbname";
                string  uid = "root";
                string  password = "root";
                string connectionString;
    
                connectionString = "SERVER=" + server + "; PORT = 3307 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                MySqlConnection connection = new MySqlConnection(connectionString);
                connection.Open();
    
            }
        }
    }

php code:

$host="servdomain.su:3307";
$port=;
$socket="";
$user="root";
$password="root";
$dbname="";

$q = "SHOW DATABASES";
$mysqli = new mysqli($host, 'root', 'root', 'dbname');

if ($result = $mysqli->query("SELECT * FROM incli_measurements")) {
    while ($row = $result->fetch_row()) {
        print_r($row);
    }
}
 print_r($mysqli);
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
 print_r($mysqli);
 echo "4564654";
 exit; 

Every time I have: Unable to connect to any of the specified MySQL hosts.

  1. FireWall turned off on client and server
  2. Users have all grants on database
  3. I've tried with other users not only from root
  4. I've tried to change default MySql server port

It looks connection string should use PWD instead of PASSWORD. Have you tried the following?

connectionString = "SERVER=" + server + "; PORT = 3307 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PWD=" + password + ";";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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