首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从另一台Ubuntu服务器访问远程MySQL数据库?

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

Stack Overflow用户
提问于 2019-05-23 20:33:54
回答 1查看 78关注 0票数 0

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

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

代码语言:javascript
复制
    $mydb = new wpdb('rruser','password','dbname', '2.2.2.2');

有了这个连接,其他一切都很好。在通过页面加载短码时,该页不会加载短码中的内容。我假设连接已超时。

有没有人能告诉我如何连接到外部数据库?我已经在"2.2.2.2“上创建了一个新用户,并授予了"dbname”权限。

代码语言:javascript
复制
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)

代码语言:javascript
复制
#
# 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

在此之前,非常感谢您。

EN

回答 1

Stack Overflow用户

发布于 2019-05-23 21:09:18

我已经解决了我的问题,在2.2.2.2的my.cnf文件中添加了绑定地址,以及允许mysql在UWF中的端口,包括TCP和8080。重新启动服务器后,问题就解决了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56275338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档