简体   繁体   中英

How to access a remote MySQL database from another Ubuntu server?

On server 1 (lets call it 1.1.1.1 , I have Wordpress installed, which has its own MySQL database. On server 2 (lets call it 2.2.2.2) , I have only MySQL on Ubuntu, with PhpMyAdmin installed.

I am attempting to connect FROM Wordpress (functions.php) FROM server 1, to server 2's MySQL database through the following:

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

Following this connection, everything else is fine. Upon loading the shortcode through a page, the page does not load the content in the shortcode. I am assuming the connection has timed out.

Please can someone advise how I can go about connecting to an external database? I have created a new user on "2.2.2.2" and granted priveleges to "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';

My MySQL my.cnf file looks like the following on the remote server which I would like to connect to (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

Many thanks in advance.

我已经通过将bind-address添加到2.2.2.2的my.cnf文件解决了我的问题,并允许在UWF中使用mysql的端口,包括TCP和8080.重启我的服务器后问题得到解决

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM