【问题标题】:How to access a remote MySQL database from another Ubuntu server?如何从另一个 Ubuntu 服务器访问远程 MySQL 数据库?
【发布时间】:2019-10-10 00:50:32
【问题描述】:

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

我正在尝试通过以下方式将 FROM 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';

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

#
# 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

非常感谢。

【问题讨论】:

    标签: mysql wordpress ubuntu phpmyadmin


    【解决方案1】:

    我通过在 2.2.2.2 的 my.cnf 文件中添加 bind-address 以及在 UWF 中允许 mysql 的端口(包括 TCP 和 8080)解决了我的问题。 重启我的服务器后问题就解决了

    【讨论】:

      猜你喜欢
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      相关资源
      最近更新 更多