如何从另一个Ubuntu服务器访问远程MySQL数据库?

时间:2019-05-23 12:33:54

标签: mysql wordpress ubuntu phpmyadmin

在服务器1上(让其称为1.1.1.1),我安装了Wordpress,它具有自己的MySQL数据库。 在服务器2(我们将其称为2.2.2.2)上,我在Ubuntu上只有MySQL,并且安装了PhpMyAdmin。

我正在尝试通过以下方式将FROM 1的Wordpress(functions.php)从服务器1连接到服务器2的MySQL数据库:

    $mydb = new wpdb('rruser','password','dbname', '2.2.2.2');

按照此连接,其他一切都很好。 通过页面加载简码后,该页面不会加载简码中的内容。我假设连接已超时。

请有人建议我如何才能连接到外部数据库? 我在“ 2.2.2.2”上创建了一个新用户,并将特权授予“ dbname”。

CREATE USER 'rruser'@'1.1.1.1' IDENTIFIED WITH mysql_native_password AS '***';`
`GRANT USAGE ON *.* TO 'rruser'@'1.1.1.1' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;`
`GRANT ALL PRIVILEGES ON `rail`.* TO 'rruser'@'1.1.1.1';

我要连接到(2.2.2.2)的远程服务器上的MySQL my.cnf文件如下所示

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
innodb_file_per_table = 1

非常感谢。

1 个答案:

答案 0 :(得分:0)

我通过将绑定地址添加到2.2.2.2的my.cnf文件中,并允许UWF中的mysql端口(包括TCP和8080)解决了我的问题。 重新启动服务器后,问题已解决