在服务器1上(让我们称之为1.1.1.1,我安装了Wordpress,它有自己的MySQL数据库。在服务器2(让我们称之为2.2.2.2)上,我只在安装了PhpMyAdmin的Ubuntu上安装了MySQL。
我正在尝试通过以下方式从服务器1的Wordpress (functions.php)连接到服务器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在此之前,非常感谢您。
发布于 2019-05-23 21:09:18
我已经解决了我的问题,在2.2.2.2的my.cnf文件中添加了绑定地址,以及允许mysql在UWF中的端口,包括TCP和8080。重新启动服务器后,问题就解决了
https://stackoverflow.com/questions/56275338
复制相似问题