启用mySQL远程连接端口3306 Plesk 11.5 CENTOS

时间:2014-03-26 09:36:33

标签: php mysql linux mysqli plesk

我在远程连接到mysql服务器时遇到问题。我们有2台运行Plesk 11.5的服务器,其中一台是linux(IP 99.99.99.99),另一台是Windows R2 2008(IP 88.88.88.88)。

注意:这些不是真正的IP地址,但为了安全起见,我已将其替换为上述地址。

我正在尝试从windows机器连接到linux机器上的mysql服务器。我使用mysqli

通过PHP脚本连接
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on '99.99.99.99' (10060) in C:\Inetpub\vhosts\oldburywells.co.uk\httpdocs\setup\includes\db.php on line 12
Failed to connect to MySQL: (2003) Can't connect to MySQL server on '99.99.99.99' (10060)

/etc/my.cnf的内容如下:

[mysqld]
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# Forced OLD_PASSWORD format is turned OFF by Plesk
#old_passwords=1
port=3306
bind-address=99.99.99.99
# skip-networking

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

在mysql数据库--db表中,主机的记录是忽略insert语句,这是我显示选项的最简单方法:

INSERT INTO `db` (`Host`, `Db`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Execute_priv`) VALUES
('%', 'designjazzsetup', 'designjazzsu', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');

用户表中的用户记录如下所示:

INSERT INTO `user` (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`) VALUES
('%', 'designjazzsu', '*812A9EC8DA3040D2FBE1FDE5A71B25011F43A358', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0);

/ etc / sysconfig / iptables的内容:

# Generated by iptables-save v1.3.5 on Tue Mar 25 10:57:08 2014
*filter
:INPUT ACCEPT [789031949:87191570991]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [261535305:1869618743997]
#-A INPUT -s 88.88.88.88 -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
COMMIT
# Completed on Tue Mar 25 10:57:08 2014

当我尝试使用端口3306上的(99.99.99.99)上的mysql telnet到linux服务器时它超时,这发生在Windows服务器(88.88.88.88)和我当地的办公室PC上。

在Windows服务器上,我的db.php包含的内容(这是尝试连接到linux mysql的服务器)如​​下所示:

<?php
session_start();
$host = "99.99.99.99";
$user = "designjazzsu";
$password = "52dJ5rH6kL77hgd!";
$db = "designjazzsetup";

$mysqli = new mysqli($host, $user, $password, $db);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
#echo $mysqli->host_info . "\n";

$mysqli = new mysqli("99.99.99.99", $user, $password, $db, 3306);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

#echo $mysqli->host_info . "\n";
?>

我花了一天多的时间才完全陷入困境。

我在linux服务器上有一个需要在两台服务器之间共享的数据库。

任何帮助都会非常感谢大家。

谢谢。

亲切的问候, 迈克尔

1 个答案:

答案 0 :(得分:0)

您无法绑定两个地址。 您可以绑定0.0.0.0地址并在防火墙中制定规则。 示例和有用的链接:

unix-linux-mysqld-server-bind-to-more-than-one-ip-address

mysql-bind-to-more-than-one-ip-address