我遇到了麻烦,我不知道该怎么做=(
我安装了MySql服务器的远程服务器(windows server 2008),服务器有专用的ip。我可以使用简单的mysqli连接从远程php客户端连接到此服务器上。但我无法使用所有其他客户端(MySqlWorkBench,C#等)从我的家用PC连接。
要从C#连接我使用:
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代码:
$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;
我每次都有: 无法连接到任何指定的MySQL主机。
答案 0 :(得分:1)
看起来连接字符串应该使用PWD而不是PASSWORD。 你试过以下这个吗?
connectionString = "SERVER=" + server + "; PORT = 3307 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PWD=" + password + ";";